Ví dụ tạo cột book_id
tự động tăng trong bảng tbl_books
Tạo
sequences
tự động tăng giá trị cho cộtbook_id
:This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersCREATE SEQUENCE public.book_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 10000 CACHE 1; ALTER TABLE public.book_id_seq OWNER TO postgres; -
Tạo bảng
tbl_books
sử dụngsequences
đã tạo trước đó:This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersCREATE TABLE public.tbl_books ( book_id bigint NOT NULL DEFAULT nextval('book_id_seq'::regclass), CONSTRAINT pk_book_id PRIMARY KEY (book_id) ) WITH ( OIDS=FALSE ); ALTER TABLE public.tbl_books OWNER TO postgres;
Không có nhận xét nào:
Đăng nhận xét