新建一張表弄喘,其中一個(gè)屬性名為UID玖喘,設(shè)置其為主鍵自增并不允許重復(fù)。
create table autotest_schema.table_test
(
UID int not null
);
create unique index table_test_UID_uindex
on autotest_schema.table_test (UID);
alter table autotest_schema.table_test
add constraint table_test_pk
primary key (UID);
新建一個(gè)序列:
CREATE SEQUENCE autotest_schema.table_test_uid_seq
START WITH 100000
INCREMENT BY 1
MINVALUE 100000
MAXVALUE 9999999999
CACHE 1;
然后手動(dòng)將序列設(shè)置為UID的默認(rèn)值
如果在某個(gè)schema下注意將schema的名字寫在表名和序列名前
alter table autotest_schema.table_test alter column uid set default nextval('autotest_schema.table_test_uid_seq');