postgresql----继承表INHERITS PARENT TABLE
使用INHERITS创建的新表会继承一个或多个父表,子表只会继承父表的表结构和NOT NULL,DEFAULT,CHECK三种约束,主键,外键和唯一键以及索引不会被继承,所以修改父表的结构(增删字段),NOT NULL,DEFAULT和CHECK约束会自动同步子表修改。
示例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的更多相关文章
- sql:sql server,MySQL,PostgreSQL的表,视图,存储过程结构查询
sql server 2005: --SQL SERVER 2005 生成代码需要知道的SQL语句 use LibrarySystem --查询当前数据库所有表和其的主键字段,字段类型,长度,是否为空 ...
- mybatis使用注解往postgresql数据库表insert数据[主键自增]的写法
建表SQL: DROP TABLE IF EXISTS person; CREATE TABLE person( person_id serial PRIMARY KEY NOT NULL, pers ...
- PostgreSQL创建表及约束
创建表 语法: create table table_name ( column_name type column_constraint, table_constraint table_constra ...
- Oracle创建表语句(Create table)语法详解及示例、、 C# 调用Oracle 存储过程返回数据集 实例
Oracle创建表语句(Create table)语法详解及示例 2010-06-28 13:59:13| 分类: Oracle PL/SQL|字号 订阅 创建表(Create table)语法详解 ...
- Postgresql实战经验之alter table 开小差了
Postgresql实战经验之alter table 开小差了 今天需要将一张有数据的表中一个字段varchar 类型转换为timestamp类型,但是pg的alter table 语句却开小差,出现 ...
- Berkeley DB的数据存储结构——哈希表(Hash Table)、B树(BTree)、队列(Queue)、记录号(Recno)
Berkeley DB的数据存储结构 BDB支持四种数据存储结构及相应算法,官方称为访问方法(Access Method),分别是哈希表(Hash Table).B树(BTree).队列(Queue) ...
- 聚簇(Cluster)和聚簇表(Cluster Table)
聚簇(Cluster)和聚簇表(Cluster Table) 时间:2010-03-13 23:12来源:OralanDBA.CN 作者:AlanSawyer 点击:157次 1.创建聚簇 icmad ...
- Postgresql两表联结更新
Postgresql两表联合更新近日使用Postgresql感到有点不好用,一个联合更新非要这样写语法才对:update d_routetripset name=b.name , descrip ...
- Innodb parent table open时导致crash
case描述: innodb中,父表和子表通过foreign constraint进行关联, 因为在更新数据时需要check 外键constraint,如果父表被大量的子表reference, 那么在 ...
随机推荐
- 关于Unity中的碰撞检测和管理(2D)
创建Unity3D项目和Unity2D项目的区别. 1.3D项目有摄像机和太阳光,2D项目只有摄像机 2.3D项目使用的贴图类型是Texture纹理,2D项目使用的贴图类型是Sprite 2D/UI ...
- imx6 uart分析
本文主要记录: 1.uart设备注册 2.uart驱动注册 3.上层应用调用有些地方理解的还不是很透彻,希望指正. 1.uart设备注册过程 MACHINE_START(MX6Q_SABRESD, & ...
- 远程桌面能连接到服务器,但PING不通
解决方法:
- e672. 缩放,剪取,移动,翻转缓冲图像
AffineTransform tx = new AffineTransform(); tx.scale(scalex, scaley); tx.shear(shiftx, shifty); tx.t ...
- HDU 1020:Encoding
pid=1020">Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- ajax basic 认证
//需要Base64见:http://www.webtoolkit.info/javascript-base64.html function make_base_auth(user, password ...
- vc 获取 硬盘序列号 和 cpu
vc 获取 硬盘序列号 和 cpu 唯一iD的方法?如题---------网上找来很多资料 也没找到, 要支持xp win7 32/64 系统下都能获取 硬盘序列号 和cpu ID 哪位朋友帮帮忙: ...
- Unity带参数的协程
两种方法都可以传递参数,代码如下: using UnityEngine; using System.Collections; public class Test : MonoBehaviour { v ...
- [mysql] Install/Remove of the Service Denied
在windos 的cmd下安装mysql 在mysql的bin目录下面执行: mysqld --install 报错: 信息如下: Install/Remove of the Service Deni ...
- 请问C#中string是值传递还是引用传递?
https://www.cnblogs.com/xiangniu/archive/2011/08/17/2143486.html 学了这么久,终于弄明白了... 是引用传递 但是string又有值传递 ...