PRIMARY KEY INDEX NAME

I would like to create a table and add a primary key to it.

As for my understanding, MS SQL adds a clustered index to the primary key and calls it the default name.

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

Thanks!

+4
source share
2 answers

Of course - you can define a PRIMARY KEY in your CREATE TABLE statement.

This will create a default PRIMARY KEY

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

but you can also fully define the name of the constraint:

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

When you create a clustered primary key, you are not creating an index, but a table organized as an index.

The default clustered primary key is used when creating a table with a primary key on SqlServer.

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

-3
source

Source: https://habr.com/ru/post/1315761/


All Articles