Primary Key Syntax

Rick Helston :

Other than visually, is there a functional difference between declaring the primary in the column definition or down at the bottom?

For example:

CREATE TABLE tbl_name (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    content TEXT
) ENGINE=InnoDB CHARSET=utf8;

Is the above different than:

CREATE TABLE tbl_name (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    content TEXT,
    PRIMARY KEY ( id )
) ENGINE=InnoDB CHARSET=utf8;
GMB :

Both syntaxes are equivalent.

The first one uses a column constraint.

The second syntax uses table constraint, and is mostly useful when you want a compound primary key, that references more than one column (in which case it is not possible to use a column constraint).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=5597&siteId=1