问题
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
回答1:
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.
回答2:
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
回答3:
You can have only one Primary key per table, but several Constraints
回答4:
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.
来源:https://stackoverflow.com/questions/16085724/what-is-the-difference-between-primary-key-only-and-primary-key-constraint