码迷,mamicode.com
首页 > 其他好文 > 详细

redshift的约束策略

时间:2015-07-06 16:12:29      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:redshift   约束   



Redshift并不提供唯一性、主外键约束,但是提供非空约束

如果在建表之前需要使用约束的效果,需要确保数据本身的合法性。

同样参考的见Create语法

UNIQUE

Keyword that specifies that the column can contain only unique values. The behavior of the unique table constraint is the same as that for column constraints, with the additional capability to span multiple columns. To define a unique table constraint, use the UNIQUE ( column_name [, ... ] ) syntax.


Important
Unique constraints are informational and are not enforced by the system.

PRIMARY KEY

Keyword that specifies that the column is the primary key for the table. Only one column can be defined as the primary key by using a column definition. To define a table constraint with a multiple-column primary key, use the PRIMARY KEY ( column_name [, ... ] ) syntax.

Identifying a column as the primary key provides metadata about the design of the schema. A primary key implies that other tables can rely on this set of columns as a unique identifier for rows. One primary key can be specified for a table, whether as a column constraint or a table constraint. The primary key constraint should name a set of columns that is different from other sets of columns named by any unique constraint defined for the same table.

Important


Primary key constraints are informational only. They are not enforced by the system, but they are used by the planner.

References reftable [ ( refcolumn ) ]

Clause that specifies a foreign key constraint, which implies that the column must contain only values that match values in the referenced column of some row of the referenced table. The referenced columns should be the columns of a unique or primary key constraint in the referenced table.

Important


Foreign key constraints are informational only. They are not enforced by the system, but they are used by the planner.

测试:
create table temp.ldc_cons_test(
id int
,name varchar(20)
,PRIMARY key (id)
,UNIQUE (id)
);

INSERT INTO temp.ldc_cons_test
SELECT 1,‘A‘
UNION ALL
SELECT 1,‘A‘
UNION ALL
SELECT 1,‘A‘

SELECT * FROM temp.ldc_cons_test

1 A
1 A
1 A

版权声明:本文为博主原创文章,未经博主允许不得转载。

redshift的约束策略

标签:redshift   约束   

原文地址:http://blog.csdn.net/tonylee0329/article/details/46773695

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!