Primary Key Constraint

Is there a difference between the two examples of creating a table? One includes the CONSTRAINT keyword, the other does not.

CREATE TABLE [dbo].[Person]( [ID] [bigint] NOT NULL, [Name] [varchar](255) NOT NULL, PRIMARY KEY CLUSTERED ([ID] ASC)) CREATE TABLE [dbo].[Person]( [ID] [bigint] NOT NULL, [Name] [varchar](255) NOT NULL, CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED ([ID] ASC)) 

I have a database with tables defined in both directions, I wonder if I will do something with it.

+4
source share
2 answers

There is no difference other than a restriction. If you do not specify one, SQL Server will create one for you, but the name of the constraint is NOT easily recognized.

I would rather provide all my database objects with good naming conventions rather than relying on the generated SQL Engine names.

+8
source

The CONSTRAINT [PK_Person] is optional. You can read about it here ; from the MSDN page:

CONSTRAINT

This is an optional keyword indicating the start of the PRIMARY KEY, NOT NULL, UNIQUE, FOREIGN KEY or CHECK definition of a constraint. Constraints are special properties that provide integrity, and they can create indexes for a table and its columns.

0
source

All Articles