postgresql----继承表inherits parent table
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了postgresql----继承表inherits parent table,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3259字,纯文字阅读大概需要5分钟。
内容图文
![postgresql----继承表inherits parent table](/upload/InfoBanner/zyjiaocheng/466/5866e347328f454b858d31c410b3a7cf.jpg)
示例1.
create table tbl_inherits_parent( a int not null, b varchar(32) not null default ‘Got u‘, c int check (c > 0), d date not null ); test=# alter table tbl_inherits_parent add constraint pk_tbl_inherits_parent_a primary key(a); ALTER TABLE test=# alter table tbl_inherits_parent add constraint uk_tbl_inherits_parent_b_d unique (b,d); ALTER TABLE test=# create table tbl_inherits_partition() inherits (tbl_inherits_parent); CREATE TABLE test=# \d tbl_inherits_partition Table "public.tbl_inherits_partition" Column | Type | Modifiers --------+-----------------------+--------------------------------------------- a | integer | not null b | character varying(32) | not null default ‘Got u‘::character varying c | integer | d | date | not null Check constraints: "tbl_inherits_parent_c_check" CHECK (c > 0) Inherits: tbl_inherits_parent
示例2.
test=# alter table tbl_inherits_parent add column e int not null default 0; ALTER TABLE test=# alter table tbl_inherits_parent alter column b set default ‘try me‘; ALTER TABLE test=# \d tbl_inherits_partition Table "public.tbl_inherits_partition" Column | Type | Modifiers --------+-----------------------+---------------------------------------------- a | integer | not null b | character varying(32) | not null default ‘try me‘::character varying c | integer | d | date | not null e | integer | not null default 0 Check constraints: "tbl_inherits_parent_c_check" CHECK (c > 0) Inherits: tbl_inherits_parent
示例3.
除继承父表之外,创建子表时可以增加自己的字段
test=# create table tbl_inherits_partition1(f int) inherits (tbl_inherits_parent); CREATE TABLE test=# \d tbl_inherits_partition1 Table "public.tbl_inherits_partition1" Column | Type | Modifiers --------+-----------------------+---------------------------------------------- a | integer | not null b | character varying(32) | not null default ‘try me‘::character varying c | integer | d | date | not null e | integer | not null default 0 f | integer | Check constraints: "tbl_inherits_parent_c_check" CHECK (c > 0) Inherits: tbl_inherits_parent
示例4.解除继承
test=# alter table tbl_inherits_partition1 no inherit tbl_inherits_parent; ALTER TABLE test=# \d tbl_inherits_partition1 Table "public.tbl_inherits_partition1" Column | Type | Modifiers --------+-----------------------+---------------------------------------------- a | integer | not null b | character varying(32) | not null default ‘try me‘::character varying c | integer | d | date | not null e | integer | not null default 0 f | integer | Check constraints: "tbl_inherits_parent_c_check" CHECK (c > 0)
postgresql----继承表inherits parent table
标签:
本文系统来源:http://www.cnblogs.com/alianbog/p/5605129.html
内容总结
以上是互联网集市为您收集整理的postgresql----继承表inherits parent table全部内容,希望文章能够帮你解决postgresql----继承表inherits parent table所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。