序列綁定字段與不綁定字段的區(qū)別
綁定字段
構造數據
drop sequence if exists test_id_seq;
create sequence test_id_seq;
drop table if exists test;
create table test(id int default nextval('test_id_seq'), name text);
alter sequence test_id_seq owned by test.id;
測試
test=# drop table test;
DROP TABLE
test=# \d
Did not find any relations.
test=#
不綁定字段
構造數據
drop sequence if exists test_id_seq;
create sequence test_id_seq;
drop table if exists test;
create table test(id int default nextval('test_id_seq'), name text);
測試
test=# drop table test;
DROP TABLE
test=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------+----------+----------
public | test_id_seq | sequence | postgres
(1 row)
test=#
總結
序列綁定字段,則刪除表的時候,序列會被一并刪除
序列不綁定字段,則序列與表是獨立的,刪除表不會將序列一并刪除
補充:PG表中字段使用序列類型以及綁定序列實例
兩種方法效果是一樣的
直接看代碼







以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
您可能感興趣的文章:- PostgreSQL Sequence序列的使用詳解
- postgresql 中的序列nextval詳解
- PostgreSQL 序列增刪改案例
- postgresql重置序列起始值的操作
- postgresql 實現更新序列的起始值
- postgresql修改自增序列操作
- Postgresql數據庫之創(chuàng)建和修改序列的操作