Is there a difference between these two create table snippets? One includes CONSTRAINT keyword, 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 ways, I'm wondering if I should do something about it.
There is no difference apart from the naming of the constraint. If you don't specify one, SQL Server will create it one for you but the name of the constraint is NOT easily recognizable.
I would prefer to give all my database objects good naming conventions instead of relying on the SQL Engine generated names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With