You are on page 1of 18

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 : RDBMS
Subject Code : CCP- 505
Topic : SQL Plus
Duration : 50 min.
Sub –Topic : DATA CONSTRAINTS
Teaching Aids : PPT
CCP505.60 1
Objectives

On completion of this period, you would be


able to know
 DEFAULT value concepts
 Examples

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

Constraints: Product code not null and primary key


Product name and specification must
be in uppercase
CCP505.60 11
Exercise – 3 (contd..)
Create Supplier master table
columns
 Supplier code
 Supplier name
 Address

Constraint : supplier code primary key and


not null

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

1. At the time of cell creation a ‘default


value’ can be assigned to it by using
_________ constraint
b) Not Null
c) Primary key
d) Foreign key
e) default.

CCP505.60 16
Frequently asked questions

1. What is default value Explain?

CCP505.60 17
Assignment

1. Alter the existing table inserting data constrains


( not null, primary key, foreign key, unique key,
check, default)

CCP505.60 18

You might also like