First, PRIMARY key
uniquely identifies a single row ( only one primary key in a table )
The
primary key should be meaningless to the user ( commonly used for indexing )
never update the primary key , or violate the principle of no meaning to the user
the primary key should not contain dynamically changing data, such as timestamp, creation time column, modified time column, etc.
In a two-table relationship, the primary key is used to refer to a specific record in one table from another table
Syntax:
CREATE TABLE table name (column name 1 data type primary key, column name 2 data type, column name 3 data type, ...);
Second, the only constraint
used to guarantee that data in a column (or set of columns) is unique, similar to a primary key, but that a table with a primary key
can contain multiple unique constraints, but only one primary key unique constraint column can be modified or updated
When you create a table, you set it by unique
Syntax:
CREATE TABLE table name (column name 1 data type unique, column name 2 data type,..。 );
Third, examples
14-sqlite's primary KEY and UNIQUE constraint