Sei sulla pagina 1di 10

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRA PRADESH

Name : M.Bhagya Lakshmi,


Designation : Lecturer in CCP,
Branch : DCCP
Institution : GMR Polytechnic, Gajwel
Semester : V Semester
Subject name : RDMS
Subject Code : CCP- 505
Topic : SQL Plus
Sub –Topic : DATA CONSTRAINTS
Duration : 50 min.
Teaching Aids : PPT
CCP505.55 1
Objectives:

On completion of the period, you would be


able to know:

 PRIMARY KEY CONCEPTS


 PRIMARY KEY as a column constraint
 PRIMARY KEY as a table constraint

CCP505.55 2
Recap:
NULL Value concepts

 While creating tables, if a row lacks a data value for a


particular column, that value is said to be null.

 Column of any data types may contain null values unless


the column was defined as not null when the table was
created.

CCP505.55 3
PRIMARY KEY CONCEPTS

 A primary key is one or more columns in a table used to


uniquely identify each row in a table.

 Primary key values must be not null and must be unique


across the column.

CCP505.55 4
PRIMARY KEY CONCEPTS (contd..)
 A multicolumn primary key is called a composite primary
key.

 The only function that a primary key performs is to


uniquely identify a row and thus if one column is used it
is just as good as if multiple columns are used.

 Multiple columns i.e. (composite keys) are used only


when the system designed requires a primary key that
cannot be contained in a simple column.

 Can contain a maximum of 16 columns.


CCP505.55 5
Example :

PRIMARY KEY as a column constraint:

CREATE TABLE client master


(client_no varchar2 (6) PRIMARY KEY, Name varchar2 (15), pin
number (6), bal_due number (10,2));

CCP505.55 6
PRIMARY KEY as a table constraint:

CREATE TABLE sales_order_details (s_order_no varchar2(6),


product_no varchar2 (6),
qty_ordered number (8), qty_disp number (8),
product_rate number (8,2),
PRIMARY KEY (s_order_no, product_no));

CCP505.55 7
SUMMARY

We have discussed about

 PRIMARY KEY CONCEPTS


 PRIMARY KEY as a column constraint
 PRIMARY KEY as a table constraint

CCP505.55 8
Quiz :

1. A multicolumn primary key is called a_______

d) Primary key
e) Unique key
f) null
g) composite primary key

CCP505.55 9
Frequently asked questions

1. Explain what is a primary key? Give example.

CCP505.55 10

Potrebbero piacerti anche