English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Usage and examples of SQL CONSTRAINT keyword

Riferimento delle parole chiave SQL

ADD CONSTRAINT

The ADD CONSTRAINT command is used to create constraints after the table is created.

The following SQL adds a constraint named 'PK_Person' on multiple columns (ID and LastName):

ALTER TABLE Persons
ADD CONSTRAINT PK_Person PRIMARY KEY (ID,LastName);

DROP CONSTRAINT

The DROP CONSTRAINT command is used to delete UNIQUE, PRIMARY KEY, FOREIGN KEY, or CHECK constraints.

Delete UNIQUE constraint

To delete the UNIQUE constraint, please use the following SQL:

SQL Server / Oracle / MS Access:

ALTER TABLE Persons
DROP CONSTRAINT UC_Person;

MySQL:

ALTER TABLE Persons
DROP INDEX UC_Person;

Delete PRIMARY constraint

To delete the PRIMARY KEY constraint, please use the following SQL:

SQL Server / Oracle / MS Access:

ALTER TABLE Persons
DROP CONSTRAINT PK_Person;

MySQL:

ALTER TABLE Persons
DROP PRIMARY KEY;

Eliminazione del vincolo FOREIGN KEY

Per eliminare il vincolo FOREIGN KEY, utilizzare il seguente SQL:

SQL Server / Oracle / MS Access:

ALTER TABLE Orders
DROP CONSTRAINT FK_PersonOrder;

MySQL:

ALTER TABLE Orders
DROP FOREIGN KEY FK_PersonOrder;

Eliminazione del vincolo CHECK

Per eliminare il vincolo CHECK, utilizzare il seguente SQL:

SQL Server / Oracle / MS Access:

ALTER TABLE Persons
DROP CONSTRAINT CHK_PersonAge;

MySQL:

ALTER TABLE Persons
DROP CHECK CHK_PersonAge;

Riferimento delle parole chiave SQL