顯示具有 MySQL 標籤的文章。 顯示所有文章
顯示具有 MySQL 標籤的文章。 顯示所有文章

2009-06-01

自動增加字段

動增加這個語法真的是好用,新增一筆資料進去,自動幫你產生一個id

Ex:
create table TableName (
SurveyId int unsigned not null auto_increment,
primary key(SurveyId))
};

auto_increment 的那個參數一定要為primary key ,如果還有其他的primary key則會發生錯誤

若已存在table:
alter table TableName add SurveyId int unsigned auto_increment , add primary key(SurveyId);


可用此語法移除
alter table OtherPrimarykeyName drop primary key;

ps. 型態不一定要用 int unsigned ,int 也行