Netezza Unique Key Constraint and Syntax

  • Post author:
  • Post last modified:February 27, 2018
  • Post category:Netezza
  • Reading time:2 mins read

Netezza nzsql supports SQL-92 standard. Netezza data warehouse appliance supports referential integrity such as Netezza unique key, primary key, and foreign keys as part of SQL-92 standard requirement. You can create Netezza unique key constraint while creating tables in Netezza database but it will not be enforced while loading Netezza tables.

Read:

In this post we will learn about the Netezza unique key constraints and its syntax.

Netezza Unique Key Constraint Syntax and Example

You can mention the Netezza Unique Key constraint when creating table in Netezza nzsql:

create table PrimaryKey_demo3 (
 col1 smallint Unique
 ,col3 varchar(300 )
) distribute on (col1);

Output:
NOTICE: unique key constraints not enforced 
CREATE TABLE

Now let us test if the Netezza unique key is enforced. You can insert duplicate values in Netezza table.

SYSTEM.ADMIN(ADMIN)=> insert into PrimaryKey_demo3 values (1,'test1'); 
INSERT 0 1 
SYSTEM.ADMIN(ADMIN)=> insert into PrimaryKey_demo3 values (1,'test1'); 
INSERT 0 1 
SYSTEM.ADMIN(ADMIN)=>

Alter Table to add Unique Key Constraint

SYSTEM.ADMIN(ADMIN)=> alter table PrimaryKey_demo3 add constraint uk_col1 unique (col1);