redshift的约束策略,redshift约束策略



官方文档:http://docs.aws.amazon.com/redshift/latest/dg/t_Defining_constraints.html
Redshift并不提供唯一性、主外键约束,但是提供非空约束
如果在建表之前需要使用约束的效果,需要确保数据本身的合法性。
同样参考的见Create语法 http://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html
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

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

相关内容