0% found this document useful (0 votes)
36 views12 pages

CCP505

This document discusses check constraints in SQL. It defines check constraints as constraints used to enforce integrity rules that can be evaluated with a logical expression. Examples are provided, such as only allowing client numbers to start with "C" or restricting cities to a set list. Check constraints are violated if the condition evaluates to false, not if true or unknown. Constraints can be added to tables on creation or later with ALTER TABLE and are stored in the data dictionary. In summary, the document covers how check constraints enforce data integrity with logical expressions and examples of check constraints.

Uploaded by

api-3849444
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views12 pages

CCP505

This document discusses check constraints in SQL. It defines check constraints as constraints used to enforce integrity rules that can be evaluated with a logical expression. Examples are provided, such as only allowing client numbers to start with "C" or restricting cities to a set list. Check constraints are violated if the condition evaluates to false, not if true or unknown. Constraints can be added to tables on creation or later with ALTER TABLE and are stored in the data dictionary. In summary, the document covers how check constraints enforce data integrity with logical expressions and examples of check constraints.

Uploaded by

api-3849444
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

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.58 1
Objectives:
On the completion of this period, you
would be able to know
 CHECK integrity constraints
 Examples

CCP505.58 2
Recap
Foreign key Constraint
 Avoids duplicates
 Not accepts null values
 Uniquely identifies the record
Unique key
 Avoids duplications
Foreign key used for references

CCP505.58 3
Introduction
 Constraints are applied to table and records
 If the data being loaded fails any of the data
constraint,
 Data is not loaded in to the cell and rejects
the entered record
 What is Check constraint ?
 How it is useful ?

CCP505.58 4
CHECK integrity constraints
 Check constraint is used to enforce integrity
rules that can be evaluated based on a logical
expression.
 CHECK constraint is never used if the
constraints can be defined using the not null,
primary key or foreign key constraint.

CCP505.58 5
Examples of CHECK constraints
 A CHECK constraint on the clients_no column
of the client_master so that no client_no value
starts with ‘C’
 A CHECK constraint on name column of the
client_master so that the name is entered in
upper case.
 A CHECK constraint on the city column of the
client_master so that only the cities
“BOMBAY”,”NEWDELHI”,”MADRAS” and
“CALCUTTA” are allowed.
CCP505.58 6
Example
CREATE TABLE client_master(client_no
varchar2(6),CONSTRAINT ck_cliento
CHECK(client_no like ‘C%’),name varchar2(15)
CONSTRAINT ck_name CHECK
(name=upper(name)),address1
varchar2(20),address2 varchar2(20),city
varchar2(15) CONSTRAINT ck_city CHECK(city
IN (‘NEW
DELHI’,BOMBAY’,’CALCUTTA’,’MADRAS’)), pin
number(6),bal_due number(10,2));

CCP505.58 7
Using Check Constraint

 A check constraint is violated only if the


condition evaluates to False.
 True and unknown values do not violate a
check column
 Make sure check constraint to defined
enforces the rule you need to enforce.

CCP505.58 8
Usage of Constraint
 Any INSERT ,UPDATE or DELETE statement
evaluates a relevant constraint ;
 The constraint must be satisfied for the statement
to succeed.

CCP505.58 9
Constraint (Contd…)
 Constraints can be connected to a table by
CREATE TABLE or ALTER TABLE command.
 Use ALTER TABLE to add or drop the constrain
from a table.
 Constraints are recorded in the data dictionary.
 If a constraint is not named , it is assigned the
name SYS_Cn, where n is an integer that
makes the name unique in the database.

CCP505.58 10
Summary

We have discussed about


 CHECK integrity constraints
 Examples

CCP505.58 11
Quiz
1. CHECK constraint is never used if the
constraints can be defined using the
________
b) not null
c) primary key
d) foreign key constraint
e) all

CCP505.58 12

You might also like