MYSQL學習二:auto_increment用法

create table ceyan(ID int not null auto_increment,
                   name varchar(20), primay key (ID));
insert into ceyan(name) values('wei xie'),('chunjiezhao'),('fei dou');

插入的值數據庫會自動給他們編號;

對已經存在的表articles想修改字段arti_ID爲auto_increment必須首先將他定義成primary key,再設置auto_increment;

alter table articles modify arti_ID int not null;
alter table articles add primary key arti_ID;
alter table articles modify arit_ID int not null auto_increment;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章