sql unique

Solutions on MaxInterview for sql unique by the best coders in the world

showing results for - "sql unique"
Bart
17 Aug 2020
1SELECT DISTINCT column1, column1, ..... FROM TABLE
2/*DISTINCT WILL NOT SELECT THE SAME VALUES IN SAME COLUMN*/
Léa
29 Nov 2018
1USE AdventureWorks2012;  
2GO  
3CREATE TABLE Production.TransactionHistoryArchive4  
4 (  
5   TransactionID int NOT NULL,   
6   CONSTRAINT AK_TransactionID UNIQUE(TransactionID)   
7);   
8GO  
9
10
Killian
03 Apr 2020
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);