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, 那么在 ...
随机推荐
- Windoows窗口程序五
程序执行机制 过程驱动-程序的执行过程是按照预订好的顺序执行. 事件驱动-程序的执行是无序,用户可以根据需要随机触发相应的事件. Win32窗口程序就是采用事件驱动方式执行,也就是消息机制. 当系统通 ...
- 关于Unity的入门游戏飞机大战的开发(上)
每个组件都是一个类的实例,要获得某个组件,要先创建一个同类型的组件类实例,然后把实例传引用过去,就可以对想要的组件实例进行操作. 做游戏一般创建一个逻辑节点,里面只管逻辑,再创建一个动画节点,里面有好 ...
- Android Activity 传递数据
activity中数据的传递方式有2中,一种是使用putExtra()传递,另外一种是传递Bundle对象,使用putExtras()方法. 方法一 发送数据 putExtra()传送的是键值对,第一 ...
- 第二百八十三节,MySQL数据库-MySQL存储过程
MySQL数据库-MySQL存储过程 MySQL存储过程,也就是有点像MySQL函数,但是他与MySQL函数是有区别的,后面会讲到函数,所以注意区分 注意:函数与存储过程的区别 存储过程是:CREAT ...
- vs2008 x64编译环境 忽略了 #ifdef WIN32
解决方法: 右键项目属性,在预处理器中添加WIN32即可 效果:
- (转)关于三星cortex A9 Sate4412 开发板 uboot 启动的一些问题释疑
说明:本文转载自:http://blog.csdn.net/gooogleman/article/details/17238079 作者:gooogleman 日 ...
- 关于RSSI的问题
1.为什么RSSI是负值,其实归根到底为什么接收的无线信号是负值,这样子是不是容易理解多了.因为无线信号多为mW级别,所以对它进行了极化,转化为dBm而已,不表示信号是负的.1mW就是0dBm,小于1 ...
- HDF5 文件格式简介
三代测序下机的原始数据不再是fastq格式了,而是换成了hdf5 格式,在做三代数据的分析之前,有必要先搞清楚hdf5 这种文件格式; 官网的链接如下:https://support.hdfgroup ...
- 【Java集合的详细研究6】Java 数组
Java 语言中提供的数组是用来存储固定大小的同类型元素. 声明数组变量 double[] myList; // 首选的方法 或 double myList[]; // 效果相同,但不是首选方法 创建 ...
- jQuery-理解事件
一.理解事件 1.什么是事件 事件是Web浏览器通知应用程序(比如我们的js)发生了某个事情! 我们可以为这些特定的事情,事先安排好处理方案,这样就能够实现互动! 2.事件目标 你可以简单的理解为事件 ...