Reputation: 13506
I am just wondering can we create a Primary key on a table in sql server without any type of index on it?
Upvotes: 8
Views: 8909
Reputation: 21
You can create a table with a primary key that is not a clustered index by adding the keyword NONCLUSTERED
after the primary key
word.
Upvotes: 2
Reputation: 824
Actually indexing functions in the same way a book is traversed. One cannot go to a particular page or topic unless there is page number and their relation to the topics. This "Paging" (ordering) of rows is done physically by Clustered Index in SQL Server. If there is no PK in a table one can add clustered index on any unique-key qualifying column(s). As there cannot be more than one clustered index on a table, and all other non-clustered indices depend on clustered index for search/traversal, you cannot make a column PK without clustered index.
Upvotes: 1
Reputation: 239684
No. As an implementation detail, SQL Server maintains the primary key using an index. You cannot prevent it from doing so. The primary key:
SQL Server already has mechanisms that offer these features - unique indexes - so it uses those to enforce the constraint.
Upvotes: 15