AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL Unique Constraint |
|
SQL > Constraint >
UNIQUE Constraint
The UNIQUE constraint ensures that all values in a column are distinct.
Key Takeaway: The SQL UNIQUE constraint prevents duplicate values from being stored in a column. Unlike PRIMARY KEY, a table can have multiple UNIQUE constraints, and UNIQUE columns may allow NULLs depending on the database.
For example, in the following CREATE TABLE statement, column "SID" has a UNIQUE constraint, and hence cannot include duplicate values. Such constraint does not hold for columns "Last_Name" and "First_Name". So, if the table already contains the following rows:
Executing the following SQL statement, will result in an error because '3' already exists in the SID column, thus trying to insert another row with that value violates the UNIQUE constraint. Please note that a column that is specified as a primary key must also be unique. At the same time, a column that's unique may or may not be a primary key. In addition, multiple UNIQUE constraints can be defined on a table. Frequently Asked Questions
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.