标签:style c class blog code java
CREATE TABLE test ( id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, username VARCHAR(15) NOT NULL )AUTO_INCREMENT = 100;
可在建表时可用“AUTO_INCREMENT=n”选项来指定一个自增的初始值。
例如,将t_user的字段ID设置为自增:(用序列sequence的方法来实现)
----创建表 Create table t_user( Id number(6),userid varchar2(20),loginpassword varchar2(20),isdisable number(6) ); ----创建序列 create sequence user_seq increment by 1 start with 1 nomaxvalue nominvalue nocache ----创建触发器 create or replace trigger tr_user before insert on t_user for each row begin select user_seq.nextval into :new.id from dual; end; ----测试 insert into t_user(userid,loginpassword, isdisable) values(‘ffll‘,‘liudddyujj‘, 0); insert into t_user(userid,loginpassword, isdisable) values(‘dddd‘,‘zhang‘, 0) select * from t_user;
MySQL Auto_Increment属性应用,布布扣,bubuko.com
标签:style c class blog code java
原文地址:http://www.cnblogs.com/binyue/p/3751767.html