浅析常用数据库的自增字段创建方法汇总
程序员文章站
2023-01-08 13:28:55
db2复制代码 代码如下:create table t1( id integer &nbs...
db2
create table t1
(
id integer not null generated always as identity (start with 1 increment by 1 minvalue 1 no maxvalue no cycle no cache order ),
...
);
oracle(需要创建一个sequence和一个trigger):
create table t1
(
id number(10,0) not null,
...
);
create sequence t1_id_seq increment by 1 start with 1 nomaxvalue nocycle cache 100 order;
create or replace trigger insert_t1_id
before insert on t1
referencing new as new old as old
for each row
begin
select t1_id_seq.nextval into :new.id from dual;
end;
mysql
create table t1
(
id int not null auto_increment,
...
);
postgresql
create table t1
(
id serial not null,
...
);
sql server
create table t1
(
id int not null identity,
...
);
sybase
create table t1
(
id int not null identity,
...
);
复制代码 代码如下:
create table t1
(
id integer not null generated always as identity (start with 1 increment by 1 minvalue 1 no maxvalue no cycle no cache order ),
...
);
oracle(需要创建一个sequence和一个trigger):
复制代码 代码如下:
create table t1
(
id number(10,0) not null,
...
);
create sequence t1_id_seq increment by 1 start with 1 nomaxvalue nocycle cache 100 order;
create or replace trigger insert_t1_id
before insert on t1
referencing new as new old as old
for each row
begin
select t1_id_seq.nextval into :new.id from dual;
end;
mysql
复制代码 代码如下:
create table t1
(
id int not null auto_increment,
...
);
postgresql
复制代码 代码如下:
create table t1
(
id serial not null,
...
);
sql server
复制代码 代码如下:
create table t1
(
id int not null identity,
...
);
sybase
复制代码 代码如下:
create table t1
(
id int not null identity,
...
);
上一篇: 女人吃什么补肾补气血比较有效果
下一篇: 咳嗽吃什么水果,原来这些水果好处这么多!