Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 780
GibboK Avatar asked Jul 15 '10 06:07

GibboK


1 Answers

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,
    ......)
like image 176
marc_s Avatar answered Sep 29 '22 01:09

marc_s