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

社会主义新天地 提交于 2020-01-23 06:28:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!