1SELECT DISTINCT column1, column1, ..... FROM TABLE
2/*DISTINCT WILL NOT SELECT THE SAME VALUES IN SAME COLUMN*/
1USE AdventureWorks2012;
2GO
3CREATE TABLE Production.TransactionHistoryArchive4
4 (
5 TransactionID int NOT NULL,
6 CONSTRAINT AK_TransactionID UNIQUE(TransactionID)
7);
8GO
9
10
1This constraint ensures all values in a column are unique.
2Example 1 (MySQL): Adds a unique constraint to the id column when
3creating a new users table.
4CREATE TABLE users (
5id int NOT NULL,
6name varchar(255) NOT NULL,
7UNIQUE (id)
8);
9Example 2 (MySQL): Alters an existing column to add a UNIQUE
10constraint.
11ALTER TABLE users
12ADD UNIQUE (id);