序列绑定字段与不绑定字段的区别
绑定字段
构造数据
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 TABLEtest=# \\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 TABLEtest=# \\d
List of relations
Schema | Name | Type | Owner --------+-------------+----------+---------- public | test_id_seq | sequence | postgres(1 row)test=#
总结
序列绑定字段,则删除表的时候,序列会被⼀并删除
序列不绑定字段,则序列与表是独⽴的,删除表不会将序列⼀并删除补充:PG表中字段使⽤序列类型以及绑定序列实例两种⽅法效果是⼀样的直接看代码
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。如有错误或未考虑完全的地⽅,望不吝赐教。
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- igat.cn 版权所有 赣ICP备2024042791号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务