Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primary Key without any index in a table?

I am just wondering can we create a Primary key on a table in sql server without any type of index on it?

like image 681
AnandPhadke Avatar asked Sep 04 '12 07:09

AnandPhadke


People also ask

Can you have primary key without index?

We want is just the primary key without any index – is that even possible? The answer is NO. It is not possible at all. If I have to say in the most simple words, Primary Keys exists with either Clustered Index or Non-Clustered Index.

Can we have a table without index?

A table without a clustered index is called a heap. With a heap, the data is not ordered by an index, so data is not stored in any particular order.

Is a primary key automatically an index?

A primary index is automatically created for the primary key and ensures that the primary key is unique. You can use the primary index to retrieve and access objects from the database. The unique index is a column, or an ordered collection of columns, for which each value identifies a unique row.

Can a table only have a primary key?

Each table can only have one primary key. Access can automatically create a primary key field for you when you create a table, or you can specify the fields that you want to use as the primary key. This article explains how and why to use primary keys. To set a table's primary key, open the table in Design view.


1 Answers

No. As an implementation detail, SQL Server maintains the primary key using an index. You cannot prevent it from doing so. The primary key:

  • Ensures that no duplicate key values exist
  • Allows individual rows to be identified/accessed

SQL Server already has mechanisms that offer these features - unique indexes - so it uses those to enforce the constraint.

like image 158
Damien_The_Unbeliever Avatar answered Sep 18 '22 15:09

Damien_The_Unbeliever