位置:首頁 > 軟件操作教程 > 數(shù)據(jù)分析 > MySQL > 問題詳情

MySQL——自增字段 auto_increment

提問人:劉旭39發(fā)布時間:2020-10-13

自增字段 auto_increment

(1)限制條件:只適用于整數(shù)類型數(shù)據(jù);數(shù)據(jù)列必須唯一索引,避免序號重復(fù);具備not null屬性;最大值限制,如int(3),大于999就不能再自增

(2)例如:創(chuàng)建xs表,包含編號(自增字段)、學(xué)號

create table xs(

id int(4) primary key auto_increment,

number int(6));

2、控制自增列的初值

(1)插入一條記錄并指定列值為所需的初值,然后插入其他記錄(比如在XS表中),5表示從序號5開始,1514為數(shù)據(jù)

例如:insert xs(id,number)

         value(5,1514);

(2)建表時定義:

create table 表名

(字段定義[,….] aoto_increment

) auto_increment=自增列初值;

例如:create table score

(id int(4) primary key auto_increment

number int(12)  )

aoto_incremrnt=自增列初始值;

繼續(xù)查找其他問題的答案?

相關(guān)視頻回答
回復(fù)(0)
返回頂部