Official Document: Http://docs.aws.amazon.com/redshift/latest/dg/t_Defining_constraints.html
redshift does not provide uniqueness, primary foreign key constraints, but provides non-null constraints
If the effect of a constraint needs to be used before the table is built, you need to ensure the legitimacy of the data itself.
See also the CREATE syntax http://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html
UNIQUE
Keyword that specifies, the column can contain only unique values. The behavior of the Unique Table constraint is the same as, a for column constraints, with the additional capability to span multiple columns. To define a unique table constraint, use the unique ( column_name [, ...]) syntax.
ImportantThe Unique constraints is informational and is not a enforced by the system.
PRIMARY KEY
Keyword that specifies, the column is the primary key for the table. Only one column can is 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 [, ...]) syn Tax.
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 is specified for a table, whether as a column constraint or a table constraint. The primary KEY constraint should name a set of columns that's different from other sets of columns named by any unique C Onstraint defined for the same table.
Important
Primary Key constraints is informational only. They is not enforced by the system, but they is used by the planner.
References
reftable[ (
Refcolumn) ]
Clause that specifies a foreign key constraint, which implies the column must contain only values that match values I n the referenced column of some row of the referenced table. The referenced columns should is the columns of a unique or PRIMARY KEY constraint in the referenced table.
Important
Foreign Key constraints is informational only. They is not enforced by the system, but they is used by the planner.
Test: CREATE TABLE temp.ldc_cons_test (ID int,name varchar), PRIMARY key (ID), UNIQUE (ID));
INSERT into Temp.ldc_cons_testselect 1, ' A ' Union allselect 1, ' A ' Union allselect 1, ' a '
SELECT * from Temp.ldc_cons_test
1 A1 A1 A
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The constraint strategy of redshift