sql unique
snippet in sql

sql select unique

user2822

 SELECT DISTINCT column1, column2, ...

 FROM table_name; 

set column as unique in sql server

user8871

ALTER TABLE Persons
ADD UNIQUE (ID);

query DISTINCT

user3620

SELECT DISTINCT Column_name FROM table_name;

DISTINCT SQL

user7687

SELECT DISTINCT column1, column1, ..... FROM TABLE
/*DISTINCT WILL NOT SELECT THE SAME VALUES IN SAME COLUMN*/

sql unique

user2756

-- To name a UNIQUE constraint, and to define a UNIQUE constraint on 
-- multiple columns, use the following SQL syntax:

-- MySQL / SQL Server / Oracle / MS Access:

CREATE TABLE Persons (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    CONSTRAINT UC_Person UNIQUE (ID,LastName)
); 

sql unique

user922

This constraint ensures all values in a column are unique.
Example 1 (MySQL): Adds a unique constraint to the id column when
creating a new users table.
CREATE TABLE users (
id int NOT NULL,
name varchar(255) NOT NULL,
UNIQUE (id)
);
Example 2 (MySQL): Alters an existing column to add a UNIQUE
constraint.
ALTER TABLE users
ADD UNIQUE (id);