PRIMARY KEY definition in MySQL CREATE TABLE statement

后端 未结 5 1867
梦如初夏
梦如初夏 2021-01-30 20:36

What\'s the difference between this code:

CREATE TABLE samples (
  sampleid INT(11) NOT NULL AUTO_INCREMENT,
  sampledate DATE NOT NULL,
  location VARCHAR(25) N         


        
5条回答
  •  太阳男子
    2021-01-30 20:55

    The second syntax is merely a shortcut allowing you to specify the column and add an index on it in a single clause.

    This works out fine in cases where you simply want to create a column and add an index on it.

    You'll need to use the first syntax if you want to do something more complicated, such as adding an index based on multiple columns rather than a single column, or if you are adding or changing an index on an existing column; that is, you are not creating the column and the index on it at the same time.

提交回复
热议问题