Skip to main content

Posts

Showing posts from September, 2017

Creating Primary Key without Clustered Index

Create a Table; Create table Test_tbl ( Id int, Name varchar (50) ) Create a clustered index on this table before creating a primary key constraint on it; Create Clustered Index Index_Name on Test_tbl(Name) Now create a primary key as below; Alter table Test_tbl add constraint Primary key (Id) Now check the type  of primary key Using this query as below;   Select object_name (object_id) as tablename, type_desc, Name, index_id, type from sys.indexes where object_name(object_id) = 'Test_tbl' 1. Clustered Index :   Clustered index is created only when both the following conditions satisfy –  The data or file, that you are moving into secondary memory should be in sequential or sorted order. There should be a key value, meaning it can not have repeated values.    Whenever you apply clustered indexing in a table, it will perform sorting in that table only. You can create only one clustered index in a table like primary k...