Unique constraints of the SQL
Unique identification of unique constraints per record in a database table.
Both the uniqueness and primary constraints provide the guarantee of a single column or set of columns.
A PRIMARY KEY constraint automatically has a unique constraint that defines it.
Please note that you can have many unique restrictions on each table, but only one primary KEY constraint per seat.
Unique SQL constraints Create a table
When the following SQL creates a "p_id" column with a unique constraint, "person" is creating a table:
CREATE TABLE Persons
(
p_id int not null,
LastName varchar (255) is not null
, FirstName varchar (255), Address
varchar (255), City
varchar (255),
UNIQUE (p_id
)
SQL Server/oracle/ms Access:
CREATE TABLE Persons
(
p_id int not NULL UNIQUE,
LastName varchar (255) Not null,< c17>
FirstName varchar (255), Address
varchar (255), City
varchar (255)
)
To make naming a unique constraint and to identify multiple columns on the unique constraints, use the following SQL syntax:
Mysql/sql Server/oracle/ms Access:
CREATE TABLE Persons (p_id int not null, LastName varchar (255) NOT NULL, FirstName varcha R (255), address varchar (255), City varchar (255), CONSTRAINT Uc_personid UNIQUE (p_id,lastname))
Database Unique constraints Change table
When you create a "p_id" column for a unique constraint, the table is already established, use the following sql:
alter TAB LE Persons ADD Unique (p_id)
To make naming a unique constraint, and determined that multiple columns are on a unique constraint, use the following SQL syntax:
ALTER TABLE Persons ADD CONSTRAINT uc_personid Unique (p_id,lastna Me)
Drop uniqueness a unique constraint
abort a unique about Bundle, use the following sql:
ALTER TABLE Persons DROP INDEX uc_personid
SQL server/oracle/ms Access:
ALTER TABLE Persons DROP CONSTRAINT uc_personid< /pre>