SlideShare a Scribd company logo
Creating a table,
populating data, adding
integrity constraints
Prepared by,
Mr. K.Vignesh Saravanan
Assistant Professor
Department of Computer Science and Engineering
Ramco Institute of Technology
Rajapalayam
Recap
Language SQL Commands
Data Definition
Language
(DDL)
1. CREATE
2. ALTER
3. DROP
4. TRUNCATE
5. RENAME
Recap
Language SQL Commands
Data Manipulation
Language
(DML)
1. INSERT
2. UPDATE
3. DELETE
Recap
Language SQL Commands
Data Control Language
(DCL)
1. GRANT
2. REVOKE
Language SQL Commands
Data Query Language
(DQL)
1. SELECT
Recap
Language SQL Commands
Transaction Control
Language
(TCL)
1. COMMIT
2. ROLLBACK
3. SAVEPOINT
Data Control Language
• DCL – to give privilege / to revoke privilege to the
users to perform DDL, DML operations
• User are given the rights (or restricted) to execute the
select, insert, update, alter, create… etc
Syntax:
GRANT(REVOKE) [privilege] on [tablename] from [users];
• > GRANT select, update on employee to 17ee001;
• > REVOKE alter, delete on employee from 17ee001;
Data Control Language
To give permission to perform all commands:
• > GRANT all on employee to 17ee001;
• > REVOKE all on employee from 17ee001;
Names
17ee001
17ee002
17ee003
17ee004
.
.
.
.
17ee060
To give permission to many users:
• > GRANT all on employee to Users;
• > REVOKE all on employee from Users;
• > REVOKE update, delete on employee
from Users;
Users
Transaction Control Language
• To control/save the changes done by the DML
commands.
• commit – It saves the state of the Database and no
previous commands can be undone.
• savepoint – creates a temporary state where we can
return to undo any changes made. To reverse any
commands we can use this savepoints.
• rollback – command use to restore to a particular
savepoint.
Transaction Control Language
NAME REGNO MARKS
AAA 1001 89
BBB 1002 90
CCC 1003 92
• > savepoint s1;
• > delete from student where marks=90;
• > savepoint s2;
• > rollback s1;
NAME REGNO MARKS
AAA 1001 89
CCC 1003 92
Transaction Control Language
NAME REGNO MARKS
AAA 1001 89
BBB 1002 90
CCC 1003 92
• > delete from student where marks=92;
• > savepoint s3;
• > commit;
• > rollback s3; # Error
• > rollback s2; # Error
• > rollback s1; # Error
NAME REGNO MARKS
AAA 1001 89
BBB 1002 90
Integrity Constraints
• Integrity – Data Quality
• Constraints – Conditions
• To ensure the quality of data in the database some
integrity constraints are used.
• KEYS
• NOT NULL
• UNIQUE
• CHECK
• DEFAULT
Integrity Constraints
Consider a student database (regno, name, marks, attd)
• Integrity constraints required are:
– Student name should not be null;
– No student regno must be same (unique regno
needed);
– Student mark will be 0 by default;
– Student attendance should be > 75;
Integrity Constraints
• NOT NULL – if the particular field should not be left
empty (i.e null values are not allowed)
• CREATE table student
(
regno int,
name varchar(20) not null,
marks int,
attd int
);
Integrity Constraints
• UNIQUE – the regno for two students should not be
same (i.e unique regno are only allowed)
• CREATE table student
(
regno int unique,
name varchar(20) not null,
marks int,
attd int
);
Integrity Constraints
• KEY – the primary key can be set to the table to
uniquely identify a tuple. (so primary key will be always
not null and unique)
• CREATE table student
(
regno int primary key,
name varchar(20) not null,
marks int,
attd int
);
Integrity Constraints
• KEY – the primary key can be set to the table to
uniquely identify a tuple. (so primary key will be always
not null and unique) (ANOTHER WAY OF DEFINING KEY)
• CREATE table student
(
regno int,
name varchar(20) not null,
marks int,
attd int,
primary key(regno)
);
Integrity Constraints
• DEFAULT– to provide a default values to the attributes
• To give the marks value to be zero.
• CREATE table student
(
regno int primary key,
name varchar(20) not null,
marks int default 0,
attd int
);
Integrity Constraints
• CHECK – to ensure if the attribute values has satisfied
the specific condition
• To check if the attendance should be >75.
• CREATE table student
(
regno int primary key,
name varchar(20) not null,
marks int default 0,
attd int check(attd>75)
);
SELECT - Restrictions
• Restricting the values:
– ALL / DISTINCT keyword;
• Select city from location;
NAME CITY
AAA SVKS
BBB SRI
CCC SRI
DDD RJPM
EEE SVKS
FFF RJPM
GGG VNR
LOCATION
CITY
SVKS
SRI
SRI
RJPM
SVKS
RJPM
VNR
select all city from location;
Same result
SELECT - Restrictions
• Restricting the values:
– ALL / DISTINCT keyword;
• To know what are the places
from which the persons are
coming:
• Select distinct city from
location;
NAME CITY
AAA SVKS
BBB SRI
CCC SRI
DDD RJPM
EEE SVKS
FFF RJPM
GGG VNR
LOCATION
CITY
SVKS
SRI
RJPM
VNR
SELECT – Pattern Matching
• Pattern matching for string:
– LIKE keyword;
• To retrieve a string data based
on a pattern (or) based on
some character
To select city names starting with
the letter ‘T’
• Select * from location
where city like ‘T%’;
NAME CITY
AAA Sivakasi
BBB Sriviliputtur
CCC Rajapalayam
DDD Sattur
EEE Tenkasi
FFF Erode
GGG Chennai
LOCATION
NAME CITY
EEE Tenkasi
SELECT – Pattern Matching
To select city names ending with
the letter ‘i’
• Select city from location
where city like ‘%i’;
To select the string from
the middle:
• Select * from location
where city like ‘_ _o_ _’;
NAME CITY
AAA Sivakasi
BBB Sriviliputtur
CCC Rajapalayam
DDD Sattur
EEE Tenkasi
FFF Erode
GGG Chennai
LOCATION
CITY
Sivakasi
Tenkasi
Chennai
NAME CITY
FFF Erode
SELECT – between
Retrieve all employees in
department 5 whose salary is
between $30,000 and $40,000.
• Select * from Employee
where salary > 30000 and
salary < 40000;
• Select * from Employee where
salary between 30000 and 40000;
NAME SALARY
AAA 10000
BBB 35000
CCC 25000
DDD 32000
EEE 41000
Employee
NAME SALARY
BBB 35000
DDD 32000
SELECT – ordering the data
Arrange the data in the table in some
particular order
(by default ascending order)
• Select * from Employee
order by salary;
NAME SALARY
AAA 10000
BBB 35000
CCC 25000
DDD 32000
EEE 41000
Employee
NAME SALARY
AAA 10000
CCC 25000
DDD 32000
BBB 35000
EEE 41000
NAME SALARY
EEE 41000
BBB 35000
DDD 32000
CCC 25000
AAA 10000
Select * from Employee
order by salary desc;
Assertions
• An assertion (statement) is a predicate
expressing a condition that
– is always expected to satisfy (or)
– The database should always satisfy
• Types:
– Domain constraints
– Referential Integrity constraints
• Ex: Customers maintain minimum balance
Rs.1000/- in their bank account
• Syntax:
create assertion assertion_name check predicate;
• Example:
create assertion min_balance check
(select * from customers where balance<500)
• Complex assertions leads to DB overhead.
• Assertions are not most widely used recently.
• Equivalent functionality can be implemented
using triggers
Authorization
• Authorization - a privilege
• Providing different levels of grants / privilege
to the database users.
– Authorization to read data
– Authorization to insert new data
– Authorization to update data
– Authorization to delete data
• SQL – DCL – includes grant and revoke
commands
• Syntax: (grant)
grant <privilege list>
on <relation name or view name>
to <user/role list>;
• Privileges can be select, insert, update, delete,
alter, etc.,
• grant select on department to Amit, Satoshi;
• grant update (budget) on department to Amit, Satoshi;
Note: user/role should be declared as public – if access to
all common users
• Syntax: (revoke)
revoke <privilege list>
on <relation name or view name>
from <user/role list>;
• revoke select on department from Amit, Satoshi;
• revoke update (budget) on department from Amit,
Satoshi;
Note: user/role should be declared as public – if access to
all common users
End of Chapter

More Related Content

What's hot

Data independence
Data independenceData independence
Data independence
Aashima Wadhwa
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
PadamNepal1
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
ER Model in DBMS
ER Model in DBMSER Model in DBMS
ER Model in DBMS
Kabindra Koirala
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
Stewart Rogers
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
Sabana Maharjan
 
Dbms 3: 3 Schema Architecture
Dbms 3: 3 Schema ArchitectureDbms 3: 3 Schema Architecture
Dbms 3: 3 Schema Architecture
Amiya9439793168
 
Database Keys
Database KeysDatabase Keys
Database Keys
Forrester High School
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
Archit Saxena
 
Create table
Create tableCreate table
Create table
Nitesh Singh
 
Tutorial On Database Management System
Tutorial On Database Management SystemTutorial On Database Management System
Tutorial On Database Management System
psathishcs
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
Anusha sivakumar
 
Dbms keys
Dbms keysDbms keys
Dbms keys
RUpaliLohar
 
SQL commands
SQL commandsSQL commands
SQL commands
GirdharRatne
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization emailharmeet
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
IshaRana14
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
Shishir Aryal
 

What's hot (20)

Data independence
Data independenceData independence
Data independence
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
ER Model in DBMS
ER Model in DBMSER Model in DBMS
ER Model in DBMS
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Dbms 3: 3 Schema Architecture
Dbms 3: 3 Schema ArchitectureDbms 3: 3 Schema Architecture
Dbms 3: 3 Schema Architecture
 
Database Keys
Database KeysDatabase Keys
Database Keys
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
Create table
Create tableCreate table
Create table
 
Tutorial On Database Management System
Tutorial On Database Management SystemTutorial On Database Management System
Tutorial On Database Management System
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
 
Dbms keys
Dbms keysDbms keys
Dbms keys
 
SQL commands
SQL commandsSQL commands
SQL commands
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 

Similar to Integrity constraints in dbms

Dbms &amp; oracle
Dbms &amp; oracleDbms &amp; oracle
Dbms &amp; oracle
J VijayaRaghavan
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
InfoRepos Technologies
 
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
DmitryLenev
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
YashaswiniSrinivasan1
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
 
Oracle Material.pdf
Oracle Material.pdfOracle Material.pdf
Oracle Material.pdf
rajeshkathavarayan
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
Md. Mahedee Hasan
 
Lab
LabLab
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
Farhan Aslam
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
Md.Mojibul Hoque
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
Vibrant Technologies & Computers
 
Mysql-overview.pptx
Mysql-overview.pptxMysql-overview.pptx
Mysql-overview.pptx
TamilHunt
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
SaurabhLokare1
 
Mutant Tests Too: The SQL
Mutant Tests Too: The SQLMutant Tests Too: The SQL
Mutant Tests Too: The SQL
DataWorks Summit
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SabrinaShanta2
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SaiMiryala1
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
BhupendraShahi6
 
Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013
Prosanta Ghosh
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
N.Jagadish Kumar
 
Dun ddd
Dun dddDun ddd

Similar to Integrity constraints in dbms (20)

Dbms &amp; oracle
Dbms &amp; oracleDbms &amp; oracle
Dbms &amp; oracle
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
Oracle Material.pdf
Oracle Material.pdfOracle Material.pdf
Oracle Material.pdf
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Lab
LabLab
Lab
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
Mysql-overview.pptx
Mysql-overview.pptxMysql-overview.pptx
Mysql-overview.pptx
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
 
Mutant Tests Too: The SQL
Mutant Tests Too: The SQLMutant Tests Too: The SQL
Mutant Tests Too: The SQL
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
Dun ddd
Dun dddDun ddd
Dun ddd
 

More from Vignesh Saravanan

Unit - 2 - Lecture-3.pdf
Unit - 2 - Lecture-3.pdfUnit - 2 - Lecture-3.pdf
Unit - 2 - Lecture-3.pdf
Vignesh Saravanan
 
Unit - I - Lecture-2.pdf
Unit - I - Lecture-2.pdfUnit - I - Lecture-2.pdf
Unit - I - Lecture-2.pdf
Vignesh Saravanan
 
Bayesian learning
Bayesian learningBayesian learning
Bayesian learning
Vignesh Saravanan
 
Case study-the next gen pos
Case study-the next gen posCase study-the next gen pos
Case study-the next gen pos
Vignesh Saravanan
 
Elaboration and domain model
Elaboration and domain modelElaboration and domain model
Elaboration and domain model
Vignesh Saravanan
 
Innovative practices jigsaw
Innovative practices   jigsawInnovative practices   jigsaw
Innovative practices jigsaw
Vignesh Saravanan
 
Innovative practices reflection
Innovative practices   reflectionInnovative practices   reflection
Innovative practices reflection
Vignesh Saravanan
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
Vignesh Saravanan
 
Database System Architecture
Database System ArchitectureDatabase System Architecture
Database System Architecture
Vignesh Saravanan
 

More from Vignesh Saravanan (9)

Unit - 2 - Lecture-3.pdf
Unit - 2 - Lecture-3.pdfUnit - 2 - Lecture-3.pdf
Unit - 2 - Lecture-3.pdf
 
Unit - I - Lecture-2.pdf
Unit - I - Lecture-2.pdfUnit - I - Lecture-2.pdf
Unit - I - Lecture-2.pdf
 
Bayesian learning
Bayesian learningBayesian learning
Bayesian learning
 
Case study-the next gen pos
Case study-the next gen posCase study-the next gen pos
Case study-the next gen pos
 
Elaboration and domain model
Elaboration and domain modelElaboration and domain model
Elaboration and domain model
 
Innovative practices jigsaw
Innovative practices   jigsawInnovative practices   jigsaw
Innovative practices jigsaw
 
Innovative practices reflection
Innovative practices   reflectionInnovative practices   reflection
Innovative practices reflection
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Database System Architecture
Database System ArchitectureDatabase System Architecture
Database System Architecture
 

Recently uploaded

Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 

Recently uploaded (20)

Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 

Integrity constraints in dbms

  • 1. Creating a table, populating data, adding integrity constraints Prepared by, Mr. K.Vignesh Saravanan Assistant Professor Department of Computer Science and Engineering Ramco Institute of Technology Rajapalayam
  • 2. Recap Language SQL Commands Data Definition Language (DDL) 1. CREATE 2. ALTER 3. DROP 4. TRUNCATE 5. RENAME
  • 3. Recap Language SQL Commands Data Manipulation Language (DML) 1. INSERT 2. UPDATE 3. DELETE
  • 4. Recap Language SQL Commands Data Control Language (DCL) 1. GRANT 2. REVOKE Language SQL Commands Data Query Language (DQL) 1. SELECT
  • 5. Recap Language SQL Commands Transaction Control Language (TCL) 1. COMMIT 2. ROLLBACK 3. SAVEPOINT
  • 6. Data Control Language • DCL – to give privilege / to revoke privilege to the users to perform DDL, DML operations • User are given the rights (or restricted) to execute the select, insert, update, alter, create… etc Syntax: GRANT(REVOKE) [privilege] on [tablename] from [users]; • > GRANT select, update on employee to 17ee001; • > REVOKE alter, delete on employee from 17ee001;
  • 7. Data Control Language To give permission to perform all commands: • > GRANT all on employee to 17ee001; • > REVOKE all on employee from 17ee001; Names 17ee001 17ee002 17ee003 17ee004 . . . . 17ee060 To give permission to many users: • > GRANT all on employee to Users; • > REVOKE all on employee from Users; • > REVOKE update, delete on employee from Users; Users
  • 8. Transaction Control Language • To control/save the changes done by the DML commands. • commit – It saves the state of the Database and no previous commands can be undone. • savepoint – creates a temporary state where we can return to undo any changes made. To reverse any commands we can use this savepoints. • rollback – command use to restore to a particular savepoint.
  • 9. Transaction Control Language NAME REGNO MARKS AAA 1001 89 BBB 1002 90 CCC 1003 92 • > savepoint s1; • > delete from student where marks=90; • > savepoint s2; • > rollback s1; NAME REGNO MARKS AAA 1001 89 CCC 1003 92
  • 10. Transaction Control Language NAME REGNO MARKS AAA 1001 89 BBB 1002 90 CCC 1003 92 • > delete from student where marks=92; • > savepoint s3; • > commit; • > rollback s3; # Error • > rollback s2; # Error • > rollback s1; # Error NAME REGNO MARKS AAA 1001 89 BBB 1002 90
  • 11. Integrity Constraints • Integrity – Data Quality • Constraints – Conditions • To ensure the quality of data in the database some integrity constraints are used. • KEYS • NOT NULL • UNIQUE • CHECK • DEFAULT
  • 12. Integrity Constraints Consider a student database (regno, name, marks, attd) • Integrity constraints required are: – Student name should not be null; – No student regno must be same (unique regno needed); – Student mark will be 0 by default; – Student attendance should be > 75;
  • 13. Integrity Constraints • NOT NULL – if the particular field should not be left empty (i.e null values are not allowed) • CREATE table student ( regno int, name varchar(20) not null, marks int, attd int );
  • 14. Integrity Constraints • UNIQUE – the regno for two students should not be same (i.e unique regno are only allowed) • CREATE table student ( regno int unique, name varchar(20) not null, marks int, attd int );
  • 15. Integrity Constraints • KEY – the primary key can be set to the table to uniquely identify a tuple. (so primary key will be always not null and unique) • CREATE table student ( regno int primary key, name varchar(20) not null, marks int, attd int );
  • 16. Integrity Constraints • KEY – the primary key can be set to the table to uniquely identify a tuple. (so primary key will be always not null and unique) (ANOTHER WAY OF DEFINING KEY) • CREATE table student ( regno int, name varchar(20) not null, marks int, attd int, primary key(regno) );
  • 17. Integrity Constraints • DEFAULT– to provide a default values to the attributes • To give the marks value to be zero. • CREATE table student ( regno int primary key, name varchar(20) not null, marks int default 0, attd int );
  • 18. Integrity Constraints • CHECK – to ensure if the attribute values has satisfied the specific condition • To check if the attendance should be >75. • CREATE table student ( regno int primary key, name varchar(20) not null, marks int default 0, attd int check(attd>75) );
  • 19. SELECT - Restrictions • Restricting the values: – ALL / DISTINCT keyword; • Select city from location; NAME CITY AAA SVKS BBB SRI CCC SRI DDD RJPM EEE SVKS FFF RJPM GGG VNR LOCATION CITY SVKS SRI SRI RJPM SVKS RJPM VNR select all city from location; Same result
  • 20. SELECT - Restrictions • Restricting the values: – ALL / DISTINCT keyword; • To know what are the places from which the persons are coming: • Select distinct city from location; NAME CITY AAA SVKS BBB SRI CCC SRI DDD RJPM EEE SVKS FFF RJPM GGG VNR LOCATION CITY SVKS SRI RJPM VNR
  • 21. SELECT – Pattern Matching • Pattern matching for string: – LIKE keyword; • To retrieve a string data based on a pattern (or) based on some character To select city names starting with the letter ‘T’ • Select * from location where city like ‘T%’; NAME CITY AAA Sivakasi BBB Sriviliputtur CCC Rajapalayam DDD Sattur EEE Tenkasi FFF Erode GGG Chennai LOCATION NAME CITY EEE Tenkasi
  • 22. SELECT – Pattern Matching To select city names ending with the letter ‘i’ • Select city from location where city like ‘%i’; To select the string from the middle: • Select * from location where city like ‘_ _o_ _’; NAME CITY AAA Sivakasi BBB Sriviliputtur CCC Rajapalayam DDD Sattur EEE Tenkasi FFF Erode GGG Chennai LOCATION CITY Sivakasi Tenkasi Chennai NAME CITY FFF Erode
  • 23. SELECT – between Retrieve all employees in department 5 whose salary is between $30,000 and $40,000. • Select * from Employee where salary > 30000 and salary < 40000; • Select * from Employee where salary between 30000 and 40000; NAME SALARY AAA 10000 BBB 35000 CCC 25000 DDD 32000 EEE 41000 Employee NAME SALARY BBB 35000 DDD 32000
  • 24. SELECT – ordering the data Arrange the data in the table in some particular order (by default ascending order) • Select * from Employee order by salary; NAME SALARY AAA 10000 BBB 35000 CCC 25000 DDD 32000 EEE 41000 Employee NAME SALARY AAA 10000 CCC 25000 DDD 32000 BBB 35000 EEE 41000 NAME SALARY EEE 41000 BBB 35000 DDD 32000 CCC 25000 AAA 10000 Select * from Employee order by salary desc;
  • 25. Assertions • An assertion (statement) is a predicate expressing a condition that – is always expected to satisfy (or) – The database should always satisfy • Types: – Domain constraints – Referential Integrity constraints • Ex: Customers maintain minimum balance Rs.1000/- in their bank account
  • 26. • Syntax: create assertion assertion_name check predicate; • Example: create assertion min_balance check (select * from customers where balance<500) • Complex assertions leads to DB overhead. • Assertions are not most widely used recently. • Equivalent functionality can be implemented using triggers
  • 27. Authorization • Authorization - a privilege • Providing different levels of grants / privilege to the database users. – Authorization to read data – Authorization to insert new data – Authorization to update data – Authorization to delete data • SQL – DCL – includes grant and revoke commands
  • 28. • Syntax: (grant) grant <privilege list> on <relation name or view name> to <user/role list>; • Privileges can be select, insert, update, delete, alter, etc., • grant select on department to Amit, Satoshi; • grant update (budget) on department to Amit, Satoshi; Note: user/role should be declared as public – if access to all common users
  • 29. • Syntax: (revoke) revoke <privilege list> on <relation name or view name> from <user/role list>; • revoke select on department from Amit, Satoshi; • revoke update (budget) on department from Amit, Satoshi; Note: user/role should be declared as public – if access to all common users