patternModerate
In SQL Server, is it possible to have a PRIMARY KEY on a table without either CLUSTERED or NONCLUSTERED indexes on the same key?
Viewed 0 times
clusteredwithoutthesameprimarysqltableindexesnonclusteredeither
Problem
In Sql Server (2008), is it possible to have a
I am aware of the fact that
But my question is to see if it is possible to create
PRIMARY KEY on a set of columns without either CLUSTERED or NONCLUSTERED indexes on the same set of columns?I am aware of the fact that
PRIMARY KEY and CLUSTERED INDEX key are separate concepts and that we can create PRIMARY KEY without CLUSTERED INDEX on it (see below). ALTER TABLE dbo.Sample
ADD CONSTRAINT PK_Sample_SeqGUID_Col1 PRIMARY KEY NONCLUSTERED (SeqGUID_Col1)But my question is to see if it is possible to create
PRIMARY KEY on a table without a CLUSTERED or NONCLUSTERED index on it.Solution
In short, no. A primary key by definition requires uniqueness, an index on the primary key field is the database engines route to enforcing this constraint.
From BOL:
When you specify a PRIMARY KEY constraint for a table, the Database
Engine enforces data uniqueness by creating a unique index for the
primary key columns. This index also permits fast access to data when
the primary key is used in queries. Therefore, the primary keys that
are chosen must follow the rules for creating unique indexes.
From BOL:
When you specify a PRIMARY KEY constraint for a table, the Database
Engine enforces data uniqueness by creating a unique index for the
primary key columns. This index also permits fast access to data when
the primary key is used in queries. Therefore, the primary keys that
are chosen must follow the rules for creating unique indexes.
Context
StackExchange Database Administrators Q#17069, answer score: 12
Revisions (0)
No revisions yet.