Академический Документы
Профессиональный Документы
Культура Документы
ANDHRA PRADESH
CCP505.56 2
Recap
Not null constraint
Primary key constraint
One or more columns in a table used to
uniquely identify each
as a column constraint
as a table constraint
CCP505.56 3
Unique Key Concepts
What is unique?
What is unique key?
A unique key is similar to a primary key
Purpose of a unique key is to ensure that
information in the column for each record is
unique
As with telephone or driver’s license
numbers.
A table may have many unique keys.
CCP505.56 4
UNIQUE as a column constraint
SQL > CREATE TABLE client_master
(client_no varchar2 (6) CONSTRAINT
clno_ukey UNIQUE, Name varchar2 (15),
pin_number (6), bal_due number (10,2));
CCP505.56 5
UNIQUE as a table constraint
SQL > CREATE TABLE client_master
(client_no varchar2 (16) name varchar2 (15),
Address1 varchar2 (20), address2 varchar2
(20), City varchar2 (15), pin number (6),
bal_due number (10,2), CONSTRAINT
clno_ukey UNIQUE (client_no));
CCP505.56 6
Unique Key- Usage
To present the duplication of values
Within the sources of a specified column
Or a set of a column in a table
Columns defined within this constraint can also
allow null values
CCP505.56 7
Composite Unique Key
Can unique key be applied on more than one
column ?
Maximum how many columns?
Unique can be defined on more than one
column - i.e., Combination of columns
Said to Composite unique key.
Maximum combination of columns is 16.
CCP505.56 8
Note
Composite key can be defined as combination
of columns
Can be applied only at table level
CCP505.56 9
Example Of Composite
Columns - Altering A Table
The table vendor_master is being altered to add
unique constraint
SQL>alter table vender_master add constraint
in_val unique (venname, tel_no);
CCP505.56 10
Summary
We have discussed about
UNIQUE KEY CONCEPTS
UNIQUE as a column constraint
UNIQUE as a table constraint
CCP505.56 11
Quiz
1. Purpose of a _______ is to ensure that
information in the column for each record
is unique
b) Not null
c) Unique key
d) Both
e) none
CCP505.56 12
Frequently asked questions
Explain unique key constraint with
example
CCP505.56 13
Assignment
1. Compare unique keys and primary key
concepts
2. Crete a table with the following constraint
defined
c) primary key
d) unique key
e) Not null
CCP505.56 14