Difference between Unique Key and Primary Keys

后端 未结 5 818
小鲜肉
小鲜肉 2020-12-16 17:44

I came across the following SQL in a book:

CREATE TABLE \'categories\'(
id SMALLINT NOT NULL AUTO INCREMENT,
category VARCHAR(30) NOT NULL,
PRIMARY KEY(\'id\         


        
5条回答
  •  生来不讨喜
    2020-12-16 18:15

    Similarity

    Both a PRIMARY and UNIQUE index create a constraint that requires all values to be distinct (1).

    Difference

    The PRIMARY key (implicitly) defines all key columns as NOT NULL; additionally, a table can only have one primary key.


    (1) Each NULL value is considered to be distinct.

提交回复
热议问题