Computer Science, asked by riya68, 1 year ago

unique constraint in sql

Answers

Answered by sana15
0
The answer is unique constraint in Shankar quarrelling lining
Answered by Anonymous
0
  • In SQL The UNIQUE constraint ensures the executed values in a column .In other words , no two rows can hold the same values for a common with UNIQUE constraint.

Let us take an example:—

CREATE TABLE statements:-

\:  \tt{CREATE  \: TABLE \: Customer } \\  \tt{( \:  \:  \:  \: SID \:integer  \:  \orange{Uni que}} \\ { \tt{Last\_na me\:var ch ar(30),}} \\ { \tt{First\_na me \:v ar ch ar(30) \:  \: ) \: }}

Column SID has a unique constraint, and hence cannot include duplicate values .Such constraint does not hold columns Last_Name and First_Name.So,it the table already contains the following rows:

\begin{array}{c|c|c}\bf SID&\bf Last\_ Na me&\bf First\_ N a m e \\1&\sf Kumar&\sf Ayush\\2&\sf Chauhan&\sf Aditya\\3&\sf Ranjan& \sf Mukul\end{array}

Excuting the following SQL commands

\tt{INSERT\:INTO\:Customer}  \:  \:  \:  \:  \:  \:  \:  \:  \:  \:  \: \\  \: \:  \:  \tt{VALUES('3','Cyrus','Grace')}

It will result in an error because the value 3 already exist in SID column , thus trying to insert another row with that value violates the UNIQUE constraint.

Similar questions