0% found this document useful (0 votes)
11 views11 pages

INTEGRITY CONSTRAINTS Dbms Presentation

The document provides an overview of SQL integrity constraints used to enforce rules on table columns, including NOT NULL, DEFAULT, UNIQUE, CHECK, PRIMARY KEY, and FOREIGN KEY. It explains the purpose of each constraint and provides examples of how to implement them in SQL table creation. The format for creating tables with constraints is also outlined.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views11 pages

INTEGRITY CONSTRAINTS Dbms Presentation

The document provides an overview of SQL integrity constraints used to enforce rules on table columns, including NOT NULL, DEFAULT, UNIQUE, CHECK, PRIMARY KEY, and FOREIGN KEY. It explains the purpose of each constraint and provides examples of how to implement them in SQL table creation. The format for creating tables with constraints is also outlined.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

INTEGRITY

CONSTRAINTS
CONTENTS
 INTRODUCTION-DEFINATION
 FORMAT
 NOT NULL
 DEFAULT
 UNIQUE
 CHECK
 PRIMARY KEY
 FOREIGN KEY
Intro-DEFINATION
 While creating tables , we may need to apply certain conditions on columns e.g.
, this column must not be blank or NULL for any record. To apply conditions on
columns , SQL constraints are used.
Hence ,
 A Constraint is a condition or check applicable on a field or set of fields.

 Some Common types of constraints that are applicable on table columns


include :-
S.NO CONSTRAINT DESCRIPTION
S
1. NOT NULL  Ensures that column cannot have NULL
value
2. DEFAULT  Provides a default value for a column
3. UNIQUE  Ensures that all values in a column are
different
4. CHECK  Ensures that value follows a certain
criteria
“FORMAT”
CREATE TABLE table_name
(
Column1 datatype(size) constraint ,
Column2 datatype(size) constraint ,
Column3 datatype(size) constraint ,
……..
);

• The create table format will be same , if want to add


a constraint then it will come on the same pace after
you define the datatype and its size without any
comma , only the space will be there between the
datatype size and constraint .
1.) NOT NULL

FOR EXAMPLE, EXPLANATION :-

CREATE TABLE customer Here,


( The column sid is of integer type and its
sid int NOT NULL , value can’t be blank or empty or NULL
f_name varchar(10) , because NOT NULL constraint is applied .
L_name varchar(10)
);
2.) DEFAULT

FOR EXAMPLE, EXPLANATION :-

CREATE TABLE student Here,


( The column Score is of integer type and its
stud_id int , default value is set to be 80 if there is
Score int DEFAULT 80 no value to be filled in , because DEFAULT
); constraint is applied .
3.) UNIQUE

FOR EXAMPLE, EXPLANATION :-

CREATE TABLE customer Here,


( The column sid is of integer type and its
Sid int UNIQUE , value will be different e.i in this column all
l_name varchar(10) , the records will be different thus unique,
f_name varchar(10) because UNIQUE constraint is applied .
);
4.) CHECK

FOR EXAMPLE, EXPLANATION :-

CREATE TABLE customer Here,


( The column sid is of integer type and its
Sid int CHECK (Sid > 0) , value will be more than 0 , because check
l_name varchar(10) , constraint is applied .
f_name varchar(10)
);
5.) PRIMARY KEY

FOR EXAMPLE,

EXPLANATION :-
CREATE TABLE customer
(
Sid int PRIMARY KEY ,
Here,
l_name varchar(10) ,
The column sid is of integer type and its
f_name varchar(10)
value will be UNIQUE as well as NOT
);
NULL and will be uniquely identified in
OR :
the table , because PRIMARY KEY
constraint is applied .
CREATE TABLE customer
(
Sid int ,
l_name varchar(10) ,
f_name varchar(10) ,
PRIMARY KEY (Sid)
);
6.) FOREIGN KEY

FOR EXAMPLE,
EXPLANATION :-

CREATE TABLE orders


( Here,
order_id int , The cust_id column in the orders table is a
order_date date , foreign key pointing to the sid column in
cust_id int , the customer table.
amount double ,
PRIMARY KEY (order_id ) ,
FOREIGN KEY ( cust_id )
references customer ( sid )
);
KHUSHI CHADHA
COURCE – BCA
SEM – 2ND
SHIFT – 2ND

You might also like