Dasso
Dasso

Reputation: 141

What is the difference between Primary Key only and Primary Key constraint?

I am very new to SQL and if my question is silly please forgive my ignorance.

What is the difference between Primary Key only and Primary Key constraint?

Difference between This

CREATE TABLE CUSTOMERS(
   ID   INT              NOT NULL,
   PRIMARY KEY (ID, NAME)

and This

CREATE TABLE CUSTOMERS(
   ID   INT              NOT NULL,
  CONSTRAINT [Pk_ID_Name] PRIMARY KEY (ID, NAME)

Thank you, Dash

Upvotes: 11

Views: 8513

Answers (4)

Raphaël Althaus
Raphaël Althaus

Reputation: 60493

In the second version, you can give a name to your constraint, allowing you to drop it using the name instead of having to name every column of a composite constraint.

Otherwise, they do the same thing.

Upvotes: 10

unom
unom

Reputation: 11476

The main difference is that the primary key column can only be created when you create/add the table or column, not later. The primary key constraint you can add any time later.

Upvotes: 1

theSoutherner
theSoutherner

Reputation: 1

You can have only one Primary key per table, but several Constraints

Upvotes: -2

Iti Tyagi
Iti Tyagi

Reputation: 3661

Well in normal and general English as well, we understand some meaning of constraint that it is a kind of limitation on something. So primary key constraint means that what are the limitations which are imposed along with making any column as a primary key.

Go through these links:Primary Key Constraint

and Primary Key

Upvotes: 1

Related Questions