您现在的位置是:网站首页> 编程资料编程资料
PostgreSQL 序列绑定字段与不绑定字段的区别说明_PostgreSQL_
2023-05-27
399人已围观
简介 PostgreSQL 序列绑定字段与不绑定字段的区别说明_PostgreSQL_
序列绑定字段与不绑定字段的区别
绑定字段
构造数据
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=#
不绑定字段
构造数据
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=#
总结
序列绑定字段,则删除表的时候,序列会被一并删除
序列不绑定字段,则序列与表是独立的,删除表不会将序列一并删除
补充:PG表中字段使用序列类型以及绑定序列实例
两种方法效果是一样的
直接看代码







以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
您可能感兴趣的文章:
相关内容
- PostGreSql 判断字符串中是否有中文的案例_PostgreSQL_
- postgresql 中position函数的性能详解_PostgreSQL_
- postgresql 中的to_char()常用操作_PostgreSQL_
- PostgreSQL 字符串处理与日期处理操作_PostgreSQL_
- PostgreSQL字符切割:substring函数的用法说明_PostgreSQL_
- Postgresql 截取字符串的案例_PostgreSQL_
- postgresql 实现字符串分割字段转列表查询_PostgreSQL_
- 教你如何在Centos8-stream安装PostgreSQL13_PostgreSQL_
- 常用 PostgreSQL 数据恢复方案及使用示例_PostgreSQL_
- 常用 PostgreSQL 预防数据丢失解决方案_PostgreSQL_
