The constraint strategy of redshift

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.