How to ADD / DROP Constraint

The CONSTRAINT creating value-exclusive column (no twins) or in other words in a single column UNIQUE constraints can not be two records with the same content.

 

The ADD / DROP CONSTRAINT Format :

ALTER TABLE <TABLE_NAME> 
ADD CONSTRAINT <CONSTRAINT_NAME> UNIQUE <FIELDNAME>;
ALTER TABLE <TABLE_NAME> 
ADD CONSTRAINT <CONSTRAINT_NAME> PRIMARY KEY <FIELDNAME>;
ALTER TABLE <TABLE_NAME> 
DROP CONSTRAINT <CONSTRAINT_NAME>;

 

The ADD / DROP CONSTRAINT Example :

ALTER TABLE TRANSACTION 
ADD CONSTRAINT CONST_TRANS_CODE UNIQUE TRANSACTION_CODE;
ALTER TABLE TRANSACTION 
ADD CONSTRAINT PK_TRANS_ID PRIMARY KEY TRANSACTION_ID;
ALTER TABLE TRANSACTION 
DROP CONSTRAINT CONST_TRANS_CODE;

 

Leave a Comment.