如何搭建視頻網(wǎng)站建站網(wǎng)站
PostgreSQL序列信息查詢
說明:
在PostgreSQL數(shù)據(jù)庫中序列和表都是序列的對象。
數(shù)據(jù)庫中不應該存在孤兒序列,序列應該和表對應的字段綁定起來。綁定后刪除表或表對應的字段后,序列會自動被刪除。
創(chuàng)建測試表和序列
create table test_t(id int,name varchar(100));
create sequence test_s;
alter sequence test_s owned by test_t.id;
信息查詢
-- PostgreSQL查看序列是否依賴于某個表(綁定到了表的字段)
select t2.relname as 表名,t3.relname as 序列名,t4.attname as 序列綁定的表的列-- ,objid as 序列oid,refobjid as 表oid,refobjsubid as 列序號from pg_depend t1join pg_class t2 on t2.oid=t1.refobjidjoin pg_class t3 on t3.oid=t1.objidjoin pg_attribute t4 on t4.attrelid=t2.oid
where 1=1and t4.attnum=t1.refobjsubidand t3.relkind='S';-- 查詢表字段上綁定的序列名稱
select pg_get_serial_sequence('表名','字段名');-- 根據(jù)模式名查看模式下的所有序列
SELECT relname FROM pg_class
WHERE relkind = 'S'
AND relnamespace IN ( SELECT oid FROM pg_namespace WHERE nspname NOT LIKE'pg_%' AND nspname != 'information_schema' );