CREATE TABLE语法
CREATE [[ GLOBAL | LOCAL ]{ TEMPORARY | TEMP }] TABLE table_name
(
{ column_name data_type [ DEFAULT default_expr ][ column_constraint [...]]
| table_constraint
| LIKE parent_table [{ INCLUDING | EXCLUDING } DEFAULTS ]
}[,...]
)
[ INHERITS ( parent_table [,...])]
[ WITH OIDS | WITHOUT OIDS ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP }]
[ TABLESPACE tablespace ]
 
紧跟在字段定义后

column_constraint
和字段定义并列写在表定义中(约束子句)

table_constraint
 
 
[CONSTRAINT constraint_name]
CHECK (expression)
[CONSTRAINT constraint_name]
CHECK ( expression )
表约
检查
NOT NULL | NULL
 
字段
约束
(修
饰词)
非空
[CONSTRAINT constraint_name]
CHECK (colunmn is not null)
[CONSTRAINT constraint_name]
CHECK (colunmn is not null)
表约
非空
UNIQUE 
[USING INDEX TABLESPACE tablespace]
[CONSTRAINT constraint_name]
UNIQUE (column_name [,...])
[USING INDEX TABLESPACE tablespace]
表索
引约
唯一
[CONSTRAINT constraint_name]
REFERENCES ref_table [( ref_column )]
[ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
[ ON DELETE action ][ ON UPDATE action ]
[CONSTRAINT constraint_name]
FOREIGN KEY ( column_name [,...])
REFERENCES ref_table [( ref_column [,...])]
[ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
[ ON DELETE action ][ ON UPDATE action ]
表外
外键
ADD [ COLUMN ]
column type [ column_constraint [...]]
ALTER [ COLUMN ] column SET DEFAULT expression
ALTER [ COLUMN ] column DROP DEFAULT
ALTER [ COLUMN ] column { SET | DROP } NOT NULL
ADD table_constraint
DROP CONSTRAINT constraint_name
[ RESTRICT | CASCADE ] CLUSTER ON index_name
相关
DDL
 

非空约束not null有两种方式实现,一种是修饰词“非空”,如 
creata table a(a int not null);
alter table a alter a drop not null; 一种是check,而check又分为字段约束和表约束,如
create table a(a int check(a is not null));
alter table a drop constraint a_a_check; 默认值default 也是通过alter语句的set和drop来进行修改的。 唯一约束unique 可以通过DROP CONSTRAINT 约束名称来删除。 在使用alter table 语句添加新字段的时候只能使用column_constraint,只有单纯添加约束才能使用table_constraint,两种情况下unique约束就存在区别。

PostgreSQL-constraint的更多相关文章

  1. PostgreSQL介绍以及如何开发框架中使用PostgreSQL数据库

    最近准备下PostgreSQL数据库开发的相关知识,本文把总结的PPT内容通过博客记录分享,本随笔的主要内容是介绍PostgreSQL数据库的基础信息,以及如何在我们的开发框架中使用PostgreSQ ...

  2. PostgreSQL数据库中的常见错误

    转载以作参考. 错误1 FATAL: connection limit exceeded for non-superusers 原因:非超级用户的连接数(max_connections - super ...

  3. 转载:postgresql分区与优化

    --对于分区表constraint_exclusion 这个参数需要配置为partition或on postgres=# show constraint_exclusion ; constraint_ ...

  4. PostgreSQL function examples

    warehouse_db=# CREATE TABLE warehouse_tbl(warehouse_id INTEGER NOT NULL,warehouse_name TEXT NOT NULL ...

  5. postgresql常用命令

    1.createdb 数据库名称 产生数据库2.dropdb 数据库名称 删除数据库 3.CREATE USER 用户名称 创建用户4.drop User 用户名称 删除用户 5.SELECT use ...

  6. 【转载】Fast Inserts to PostgreSQL with JDBC and COPY FROM

    source: http://rostislav-matl.blogspot.com/2011/08/fast-inserts-to-postgresql-with-jdbc.html Thanks ...

  7. Fluent NHibernate and Mysql,SQLite,PostgreSQL

    http://codeofrob.com/entries/sqlite-csharp-and-nhibernate.html https://code.google.com/archive/p/csh ...

  8. PostgreSQL Partitions

    why we need partitions The first and most demanding reason to use partitions in a database is to inc ...

  9. PostgreSQL index types and index bloating

    warehouse_db=# create table item (item_id integer not null,item_name text,item_price numeric,item_da ...

  10. PostgreSQL数据库中跨库访问解决方案

    PostgreSQL跨库访问有3种方法:Schema,dblink,postgres_fdw. 方法A:在PG上建立不同SCHEMA,将数据和存储过程分别放到不同的schema上,经过权限管理后进行访 ...

随机推荐

  1. linker command failed with exit code

    转载 : http://blog.csdn.net/chengwuli125/article/details/25051741

  2. Java中写文件操作

    OutputStream 和 Writer OutputStream类(直接操作byte数组) 该类是字节输出流的抽象类,定义了输出流的各种操作方法.如下图是OutputStream的层次结构: By ...

  3. MVC学习系列8--分页和排序

    分页和排序,应该是软件开发中,需要必知必会的技能了,对于分页,网上很多教程,当然,别人终究是别人的,只有自己理解,会了,并且吸收之后,再用自己的语言,传授出来,这才是硬道理.好了,废话说多了.现在我们 ...

  4. FreeRTOS 中断优先级嵌套错误引发HardFault异常解决(转)

      最近在使用FreeRTOS的时候,突然发现程序在运行了几分钟之后所有的任务都不再调用了,只有几个中断能正常使用,看来是系统挂掉了,连续测试了几次想找出问题,可是这个真的有点不知所措.      我 ...

  5. WPF资源使用

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...

  6. ListView灵活的用法

    以下是示例的效果图: WinForm的ListView控件是可以分组显示的,还可排序. 可以把ListView的View属性设置为Details 完整项目请到下面网址查找下载 http://hover ...

  7. discuz X3.1 关于分表 和 分表数据迁移

    // *********** 关于读取分表的数据*********** { // forum_thread 分表代码片段 -- 帖子列表 { // 定位某个板块的帖子落在哪个表(forum_threa ...

  8. hdu-2063-二分图最大匹配

    过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  9. Singleton

    1.//懒汉模式 //天生线程不安全,但是效率高 public class Singleton { private static Singleton singleton; private Single ...

  10. Dumpbin 工具的使用

    dumpbin用法:dumpbin /exports /out:d:\mfc90.txt d:\mfc90.lib 在使用VC时,可以用DUMPBIN.EXE来得到某个DLL中所输出的符号的清单.如下 ...