這篇文章主要介紹了PostgreSQL 序列綁定字段與不綁定字段的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
序列綁定字段與不綁定字段的區(qū)別
綁定字段
構(gòu)造數(shù)據(jù)
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=#
不綁定字段
構(gòu)造數(shù)據(jù)
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=#
總結(jié)
序列綁定字段,則刪除表的時候,序列會被一并刪除
序列不綁定字段,則序列與表是獨立的,刪除表不會將序列一并刪除
補充:PG表中字段使用序列類型以及綁定序列實例
兩種方法效果是一樣的
直接看代碼







文章來源:腳本之家
來源地址:https://www.jb51.net/article/205199.htm
申請創(chuàng)業(yè)報道,分享創(chuàng)業(yè)好點子。點擊此處,共同探討創(chuàng)業(yè)新機遇!