oracle自增列一般通过trigger来实现。 如: ---创建序列(SEQUENCE) CREATE SEQUENCE s_id NOMAXVALUE NOCYCLE ---创建触发器(TRIGGER) CREATE OR REPLACE TRIGGER BEFORE_INSERT_T_XXX BEFORE INSERT ON "T_XXX" FOR EACH ROW begin select s_id.nextval into :new.COL_ID from dual; end;SQL Server通过identity来实现: create table (id int identity, name varchar(10) )
创建两个表,用来做测试: create table test (id int,name varchar2(10)); create table test1 (id int,name varchar2(10));创建sequence,用来得到自动增长值: create sequence For_test increment by 1 start with 1 maxvalue 999999999 nocycle cache 10;测试: insert into test(id,name) values(For_test.Nextval,'Hello'); insert into test(id,name) values(For_test.Nextval,'World'); insert into test1(id,name) values(For_test.Nextval,'OK');查询测试数据: sql>select * from test; id name ---------------- 1 Hello 2 World sql>select * from test1; id name ---------------- 3 OK说明: 从上面的例子中我们看到,我们创建一个sequence用来获得一个自动增长的值(这和sql server中的实现不同),但同时这个sequence可以同时用于多个数据表,并且为不同数据表获取的自动增长值是不重复的.问题: 如果要为一个表单独创建一个sequence,就是说别的表不能使用该sequence,oracle是否可以做到;或者有没有其他的办法为oracle数据表设置自动增长列?本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/am2004/archive/2005/12/15/553342.aspx
如:
---创建序列(SEQUENCE)
CREATE SEQUENCE s_id NOMAXVALUE NOCYCLE ---创建触发器(TRIGGER)
CREATE OR REPLACE TRIGGER BEFORE_INSERT_T_XXX
BEFORE INSERT ON "T_XXX" FOR EACH ROW
begin
select s_id.nextval into :new.COL_ID from dual;
end;SQL Server通过identity来实现:
create table
(id int identity,
name varchar(10)
)
create table test
(id int,name varchar2(10));
create table test1
(id int,name varchar2(10));创建sequence,用来得到自动增长值:
create sequence For_test
increment by 1
start with 1
maxvalue 999999999
nocycle
cache 10;测试:
insert into test(id,name) values(For_test.Nextval,'Hello');
insert into test(id,name) values(For_test.Nextval,'World');
insert into test1(id,name) values(For_test.Nextval,'OK');查询测试数据:
sql>select * from test;
id name
----------------
1 Hello
2 World
sql>select * from test1;
id name
----------------
3 OK说明:
从上面的例子中我们看到,我们创建一个sequence用来获得一个自动增长的值(这和sql server中的实现不同),但同时这个sequence可以同时用于多个数据表,并且为不同数据表获取的自动增长值是不重复的.问题:
如果要为一个表单独创建一个sequence,就是说别的表不能使用该sequence,oracle是否可以做到;或者有没有其他的办法为oracle数据表设置自动增长列?本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/am2004/archive/2005/12/15/553342.aspx
oracle中1使用后,使用2。而sql server中
表1使用1后,表1从2开始。
但表2仍然可以从1开始。