PostgreSQL 序列綁定字段與不綁定字段的區(qū)別說明
更新時間:2021年02月01日 15:46:51 作者:岳麓丹楓001
這篇文章主要介紹了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表中字段使用序列類型以及綁定序列實例
兩種方法效果是一樣的
直接看代碼
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章
Postgres 創(chuàng)建Role并賦予權(quán)限的操作
這篇文章主要介紹了 Postgres 創(chuàng)建Role并賦予權(quán)限的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-01-01Postgresql psql文件執(zhí)行與批處理多個sql文件操作
這篇文章主要介紹了Postgresql psql文件執(zhí)行與批處理多個sql文件操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-01-01postgresql實現(xiàn)對已有數(shù)據(jù)表分區(qū)處理的操作詳解
這篇文章主要為大家詳細(xì)介紹了postgresql實現(xiàn)對已有數(shù)據(jù)表分區(qū)處理的操作的相關(guān)知識,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-12-12解決PostgreSQL數(shù)據(jù)庫連接報錯:psql:?error:?FATAL:?password?authent
這篇文章主要給大家介紹了關(guān)于如何解決PostgreSQL數(shù)據(jù)庫連接報錯:psql:?error:?FATAL:?password?authentication?failed?for?user?"postgres"的相關(guān)資料,在使用PostgreSQL時,一些關(guān)鍵配置的錯誤可能導(dǎo)致數(shù)據(jù)庫無法正常啟動,需要的朋友可以參考下2024-05-05