當(dāng)前位置:首頁(yè) >  站長(zhǎng) >  數(shù)據(jù)庫(kù) >  正文

PostgreSQL 序列綁定字段與不綁定字段的區(qū)別說(shuō)明

 2021-04-30 16:22  來(lái)源: 腳本之家   我來(lái)投稿 撤稿糾錯(cuò)

  域名預(yù)訂/競(jìng)價(jià),好“米”不錯(cuò)過(guò)

這篇文章主要介紹了PostgreSQL 序列綁定字段與不綁定字段的區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

序列綁定字段與不綁定字段的區(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;

 

測(cè)試

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);

 

測(cè)試

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é)

序列綁定字段,則刪除表的時(shí)候,序列會(huì)被一并刪除

序列不綁定字段,則序列與表是獨(dú)立的,刪除表不會(huì)將序列一并刪除

補(bǔ)充:PG表中字段使用序列類(lèi)型以及綁定序列實(shí)例

兩種方法效果是一樣的

直接看代碼

文章來(lái)源:腳本之家

來(lái)源地址:https://www.jb51.net/article/205199.htm

申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!

相關(guān)文章

熱門(mén)排行

信息推薦