GibboK
GibboK

Reputation: 73928

INDEX NAME on PRIMARY KEY

I would like create a table and add to it a Primary Key.

As for my understanding MS SQL add a clustered Index on the Primary Key and will name it with a default name.

I would like to know if is possible create a table and ASSIGN a custom name for the index created by default or how can i change the default name after the table as been created.

Thanks!

Upvotes: 5

Views: 5802

Answers (2)

marc_s
marc_s

Reputation: 754538

Sure - you can define the PRIMARY KEY constraint in your CREATE TABLE statement.

This will generate the default PRIMARY KEY

CREATE TABLE dbo.Table
  (ID INT IDENTITY PRIMARY KEY,
    .......)

but you can totally define the name of the constraint, too:

CREATE TABLE dbo.Table2
  (ID INT IDENTITY CONSTRAINT PK_Table2 PRIMARY KEY,
    ......)

Upvotes: 13

x77
x77

Reputation: 737

When you create a Clustered Primary Key, you do´nt create a index, but a Table organized as index.

Clustered Primary key is default option when you create a table with primary key on SqlServer.

http://msdn.microsoft.com/en-us/library/aa933131(SQL.80).aspx

Upvotes: -3

Related Questions