CLUSTERED
Example
Section titled “Example”CREATE TABLE Orders( OrderID int PRIMARY KEY CLUSTERED, OrderNumber int NOT NULL, CustomerName varchar(255) NOT NULL, OrderDate date);Output
Section titled “Output”Commands executed successfully.Explanation
Section titled “Explanation”The given SQL statement creates a new table named Orders with OrderID, OrderNumber, CustomerName, and OrderDate fields. The OrderID field is defined as the primary key and it is clustered. In SQL Server, a clustered index determines the physical order of data in a table, thus the table data rows are sorted and stored in order according to the clustered index. Here, the OrderID field is the clustered index of the Orders table.
Example
Section titled “Example”CREATE CLUSTERED INDEX idx_nameON table_name (column_name);Output
Section titled “Output”Index created.Explanation
Section titled “Explanation”In the provided example, a CLUSTERED index named idx_name is created on the column column_name of the table table_name. The CLUSTERED index physically reorders the rows in the table to match the index.