Answers for "unique constraint ("

SQL
7

constraint unique sql

ALTER TABLE table_name ADD CONSTRAINT cst_name UNIQUE (col_name); 
ALTER TABLE table_name ADD CONSTRAINT cst_name UNIQUE (col1, col2); -- Multiple
ALTER TABLE table_name ADD col_name NUMBER UNIQUE;				  	-- New field
Posted by: Guest on July-03-2021
-1

unique constraint

CREATE TABLE Students ( 	 /* Create table with a single field as unique */
    ID INT NOT NULL UNIQUE
    Name VARCHAR(255)
);

CREATE TABLE Students ( 	 /* Create table with multiple fields as unique */
    ID INT NOT NULL
    LastName VARCHAR(255)
    FirstName VARCHAR(255) NOT NULL
    CONSTRAINT PK_Student
    UNIQUE (ID, FirstName)
);

ALTER TABLE Students 	 /* Set a column as unique */
ADD UNIQUE (ID);

ALTER TABLE Students 	 /* Set multiple columns as unique */
ADD CONSTRAINT PK_Student 	 /* Naming a unique constraint */
UNIQUE (ID, FirstName);
Posted by: Guest on July-06-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language