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 也行

沒有留言:

張貼留言

有問題就留下吧,盡力而為回答。不要留垃圾訊息就好!