sql中的串行数据类型

时间:2012-04-02 07:26:44

标签: sql database postgresql

我正在使用postgresql,我想创建一个自动生成的数据类型'serial'列(从1000开始,步数为100)。

我该怎么办?

1 个答案:

答案 0 :(得分:3)

PostgreSQL有很好的文档。您可以创建序列: http://www.postgresql.org/docs/current/static/sql-createsequence.html 然后使用SERIAL列创建表: http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL

CREATE SEQUENCE my_table1_seq START 1000 INCREMENT 100;
CREATE TABLE table1 (id integer NOT NULL DEFAULT nextval('my_table1_seq'), txt varchar(1000));
INSERT INTO table1 (txt) VALUES ('zorro1');
INSERT INTO table1 (txt) VALUES ('zorro2');
INSERT INTO table1 (txt) VALUES ('zorro3');
SELECT * FROM table1;