Professional Documents
Culture Documents
ANDHRA PRADESH
Name : M.Bhagya Lakshmi,
Designation : Lecturer in CCP,
Branch : DCCP
Institution : GMR Polytechnic, Gajwel
Semester : V Semester
Subject name : RDBMS
Subject Code : CCP- 505
Topic : SQL Plus
Duration : 50 min.
Sub –Topic : DATA CONSTRAINTS
Teaching Aids : PPT
CCP505.60 1
Objectives
CCP505.60 2
Recap
Check integrity constraints
Enforce integrity rules that can be
evaluated based on a logical expression
Check constraint not used when not null,
primary key & foreign key are used
Restrictions on check integrity constraints.
CCP505.60 3
Default constraint
What is default?
Default means generated automatically if
no value is given by the user
Default value means?
At the time of cell creation a Default value
is assigned to it
CCP505.60 4
DEFAULT value concepts
When the user is loading a record with values
and leaves a cell empty,
DBA will automatically load this cell with the
default value specified.
The data type of the default value should match
the data type of the column.
CCP505.60 5
Example
CREATE TABLE acmast (acno number (4)
PRIMARY KEY, Acname varchar2 (15) NOT NULL,
actype char (1) DEFAULT 'S', Loc varchar2 (15),
bal number (9,2), Intro number (4), remarks
varchar2 (40));
CCP505.60 6
Exercise - 1
Create table STORES with followings columns
ITEMNO
ITEM_NAME
QTY_PRUCHASES
QTY_ISSUED
CURBAL
RATE
With following constraints
ITEMNO – NOT NULL and PRIMARY KEY
CCP505.60 7
Exercise - 2
Create table TRANS with following columns
INDENTNO
TRANSDATE
DEPT_SUPPLIER
ITEMNO
TRTYPE(I or R)
QTY
RATE
CCP505.60 8
Exercise – 2 (contd..)
Create table SUPPLIER,DEPT
SUPPLIER
SUPPCODE
SUPPLIER
DEPT
DEPTNO
DEPTNAME
CCP505.60 9
Exercise -2 (contd..)
CONSTRAINTS
ITEMNO(INDENTNO,TRANSDATE),SUPPCODE
(DEPTNO) –NOT NULL & PRIMARY KEY
TRANS,ITEMNO REFERS STORES,ITEM NO
TRTYPE I or R
CCP505.60 10
Exercise - 3
Product master table
Columns
Product code
Product name
Unit of operation
Specification
Rate
CCP505.60 12
Exercise – 3 (contd..)
Create Order table
Columns
Product code
Supplier code
Quantity
Rate
Order date
Received date
CCP505.60 13
Exercise – 3 (contd..)
Constraints:
Product code and supplier code form primary
key.
Product code and supplier code are foreign
keys references product master and supplier
master.
CCP505.60 14
Summary
We have discussed about
DEFAULT value concepts
Examples
CCP505.60 15
Quiz
CCP505.60 16
Frequently asked questions
CCP505.60 17
Assignment
CCP505.60 18