可以创建一个序列,它会自动递增rank列的值。
CREATE SEQUENCE rank_id_seq; CREATE TABLE yourtable ( rank INTEGER NOT NULL default nextval('rank_id_seq'),username VARCHAR(20) NOT NULL,password VARCHAR(50) NOT NULL ); ALTER SEQUENCE rank_id_seq owned by yourtable.rank;