Integrity Constraints in DBMS
Mrs. Pallavi Patil
Data integrity constraints
• Integrity means correctness and completeness of data. Constraints
means restriction.
• Integrity constraints means the mechanism used to prevent invalid
data entry into table.
Mrs. Pallavi Patil
i. Primary key constraint
 It prevents duplication of data values within column and also does not
allow null valuse.
Syntax:
Create table table_name(column_name datatype (size) primary key);
Ex. Create table Student(Rollno number(5) primary key, Stud_name
varchar2(20), marks number(4,2));
ii. Foreign key constraint
• also called referential integrity constraint.
• Develops parent-child relationship between two tables.
• value of foreign key is derived from primary key of parent table.
Mrs. Pallavi Patil
• Primary key is present in parent table and foreign key is present in child
table.
Syntax:
Create table table_name( column_name datatype (size), foreign
key(column_name) references parent table_name(column_name));
Ex.
Create table department( empno number (5), foreign key(emp_number)
references emp(emp_no));
Mrs. Pallavi Patil
Unique key constraint
• It is used to prevent duplicate data entry within specified column.
• It allows null values.
Syntax:
Create table table_name(ColumnName datatype(size) unique);
Create table Student(Rollno number(5) unique, Stud_name varchar2(20));
Mrs. Pallavi Patil
Default constraint
• It is used to assign default value to the column.
• The default value is added to all new records if no other value is
specified.
Ex. Create table Student(Rollno number(5) , Stud_name
varchar2(20), stud_city varchar( 15) default ‘sangli’);
Mrs. Pallavi Patil
Not null constraint
• By default all columns allow null values, but when not null constraint is
enforced for the column, then that column does not allow null values.
Syntax:
Create table tableName(column_name datatype(size) not null);
Ex. Create table Student(Rollno number(5) , Stud_name varchar2(20) not
null);
Check constraint
• These constraints defines the condition that each row must satisfied.
• Single column can have multiple check constraints.
Mrs. Pallavi Patil
Syntax
Create table table_name(column_name datatype(size) check(condition));
Ex.
Create table Student(Rollno number(5), Stud_name varchar2(20), marks
number(4,2) check(marks > 40));
Mrs. Pallavi Patil

Integrity Constraints in Database Management System.pptx

  • 1.
    Integrity Constraints inDBMS Mrs. Pallavi Patil
  • 2.
    Data integrity constraints •Integrity means correctness and completeness of data. Constraints means restriction. • Integrity constraints means the mechanism used to prevent invalid data entry into table. Mrs. Pallavi Patil
  • 3.
    i. Primary keyconstraint  It prevents duplication of data values within column and also does not allow null valuse. Syntax: Create table table_name(column_name datatype (size) primary key); Ex. Create table Student(Rollno number(5) primary key, Stud_name varchar2(20), marks number(4,2)); ii. Foreign key constraint • also called referential integrity constraint. • Develops parent-child relationship between two tables. • value of foreign key is derived from primary key of parent table. Mrs. Pallavi Patil
  • 4.
    • Primary keyis present in parent table and foreign key is present in child table. Syntax: Create table table_name( column_name datatype (size), foreign key(column_name) references parent table_name(column_name)); Ex. Create table department( empno number (5), foreign key(emp_number) references emp(emp_no)); Mrs. Pallavi Patil
  • 5.
    Unique key constraint •It is used to prevent duplicate data entry within specified column. • It allows null values. Syntax: Create table table_name(ColumnName datatype(size) unique); Create table Student(Rollno number(5) unique, Stud_name varchar2(20)); Mrs. Pallavi Patil
  • 6.
    Default constraint • Itis used to assign default value to the column. • The default value is added to all new records if no other value is specified. Ex. Create table Student(Rollno number(5) , Stud_name varchar2(20), stud_city varchar( 15) default ‘sangli’); Mrs. Pallavi Patil
  • 7.
    Not null constraint •By default all columns allow null values, but when not null constraint is enforced for the column, then that column does not allow null values. Syntax: Create table tableName(column_name datatype(size) not null); Ex. Create table Student(Rollno number(5) , Stud_name varchar2(20) not null); Check constraint • These constraints defines the condition that each row must satisfied. • Single column can have multiple check constraints. Mrs. Pallavi Patil
  • 8.
    Syntax Create table table_name(column_namedatatype(size) check(condition)); Ex. Create table Student(Rollno number(5), Stud_name varchar2(20), marks number(4,2) check(marks > 40)); Mrs. Pallavi Patil