SlideShare uma empresa Scribd logo
1 de 31
SQL and Integrity
Constraints
By:D-Mishra
Concept of DDL, DML, DCL
Structured Query Language(SQL) as we all know is the
database language by the use of which we can perform
certain operations on the existing database and also we
can use this language to create a database. Sql uses
certain commands like Create, Drop, Insert, etc.
DDL – Data Definition Language
Data Definition Language actually consists of the SQL commands that
can be used to define the database schema. It simply deals with
descriptions of the database schema and is used to create and modify
the structure of database objects in the database.DDL is a set of SQL
commands used to create, modify, and delete database structures but
not data. These commands are normally not used by a general user,
who should be accessing the database via an application.
● CREATE: This command is used to create the database or its objects
(like table, index, function, views, store procedure, and triggers).
● DROP: This command is used to delete objects from the database.
● ALTER: This is used to alter the structure of the database.
● TRUNCATE: This is used to remove all records from a table,
including all spaces allocated for the records are removed.
● COMMENT: This is used to add comments to the data dictionary.
● RENAME: This is used to rename an object existing in the database.
DQL (Data Query Language)
DQL statements are used for performing queries on the data within
schema objects. The purpose of the DQL Command is to get some
schema relation based on the query passed to it. We can define
DQL as follows it is a component of SQL statement that allows
getting data from the database and imposing order upon it. It
includes the SELECT statement. This command allows getting the
data out of the database to perform operations with it. When a
SELECT is fired against a table or tables the result is compiled into
a further temporary table, which is displayed or perhaps received
by the program i.e. a front-end.
● SELECT: It is used to retrieve data from the database.
DML(Data Manipulation Language)
DML or Data Manipulation Language and this includes most of
the SQL statements. It is the component of the SQL statement
that controls access to data and to the database. Basically, DCL
statements are grouped with DML statements
● INSERT: It is used to insert data into a table.
● UPDATE: It is used to update existing data within a
table.
● DELETE : It is used to delete records from a database
table.
● LOCK: Table control concurrency.
● CALL: Call a PL/SQL or JAVA subprogram.
● EXPLAIN PLAN: It describes the access path to data.
DCL (Data Control Language)
DCL includes commands such as GRANT and REVOKE which mainly
deal with the rights, permissions, and other controls of the database
system.
● GRANT:This command gives users access privileges to the database.
● REVOKE: This command withdraws the user’s access privileges given by using the GRANT command.
Basic Structure
● Applications: – It can be considered as a user-friendly web
page where the user enters the requests. Here he simply...
● End User: – They are the real users of the database. They
can be developers, designers, administrators, or the
actual...
● DDL: – Data Definition Language (DDL) is a query fired to
create database, schema, tables, mappings, etc in the
database.
● DDL Compiler: – This part of the database is responsible
for processing the DDL commands. That means this
compiler...
Set operations
Union
Union combines two different results obtained by a query into a single result in the form of
a table. However, the results should be similar if union is to be applied on them.
Syntex:
Select Student_Name from Art_Students
UNION
Select Student_Name from Dance_Students
Intersection
The intersection operator gives the common data values between the two data
sets that are intersected. The two data sets that are intersected should be similar
for the intersection operator to work. Intersection also removes all duplicates
before displaying the result.
Syntex:
Select Student_Name from Art_Students
INTERSECT
Select Student_Name from Dance_Students
Aggregate Functions
COUNT FUNCTION
● COUNT function is used to Count the number of rows in a database table. It can work on both numeric and non-
numeric data types.
● COUNT function uses the COUNT(*) that returns the count of all the rows in a specified table. COUNT(*)
considers duplicate and Null.
Syntax
1. COUNT(*)
2. or
3. COUNT( [ALL|DISTINCT] expression )
SUM Function
Sum function is used to calculate the sum of all selected columns. It works on numeric fields only.
Syntax
1. SUM()
2. or
3. SUM( [ALL|DISTINCT] expression )
AVG function
The AVG function is used to calculate the average value of the numeric type. AVG function returns the average of all
non-Null values.
Syntax
1. AVG()
2. or
3. AVG( [ALL|DISTINCT] expression )
MAX Function
MAX function is used to find the maximum value of a certain column. This function determines the largest value of all
selected values of a column.
Syntax
MAX()
1. or
2. MAX( [ALL|DISTINCT] expression )
MIN Function
MIN function is used to find the minimum value of a certain column. This function determines the smallest value of all selected
values of a column.
Syntax
1. MIN()
2. or
3. MIN( [ALL|DISTINCT] expression )
Domain constraints in DBMS
● Domain constraints
● Entity Integrity constraints
● Referential Integrity constraints
● Key constraints
Domain Constraints
Domain Constraints are user-defined columns that help the user
to enter the value according to the data type. And if it encounters
a wrong input it gives the message to the user that the column is
not fulfilled properly. Or in other words, it is an attribute that
specifies all the possible values that the attribute can hold like
integer, character, date, time, string, etc.
Domain Constraints – Not Null: Null values are the values that are unassigned or we can also say that which are
unknown or the missing attribute values and by default, a column can hold the null values.
Create table employee
(employee_id varchar(30),
employee_name varchar(30) not null,
salary NUMBER);
Domain Constraints – Check: It defines a condition that each row must satisfy which means it restricts the
value of a column between ranges or we can say that it is just like a condition or filter checking before saving
data into a column. It ensures that when a tuple is inserted inside the relation must satisfy the predicate
given in the check clause.
Create table employee
(employee_id varchar(30) not
null check(employee_id > 0),
employee_name varchar(30),
salary NUMBER);
Integrity Constraints
Domain constraints
● Domain constraints can be defined as the definition of a valid set of
values for an attribute.
● The data type of domain includes string, character, integer, time, date,
currency, etc. The value of the attribute must be available in the
corresponding domain.
Entity integrity constraints
● The entity integrity constraint states that primary key value can't be null.
● This is because the primary key value is used to identify individual rows in
relation and if the primary key has a null value, then we can't identify those
rows.
● A table can contain a null value other than the primary key field.
Referential Integrity Constraints
● A referential integrity constraint is specified between two tables.
● In the Referential integrity constraints, if a foreign key in Table 1
refers to the Primary Key of Table 2, then every value of the Foreign
Key in Table 1 must be null or be available in Table 2.
Key constraints
● Keys are the entity set that is used to identify an entity within its entity
set uniquely.
● An entity set can have multiple keys, but out of which one key will be
the primary key. A primary key can contain a unique and null value in
the relational table.
SQL and Integrity Constraints (2).pptx
SQL and Integrity Constraints (2).pptx

Mais conteúdo relacionado

Semelhante a SQL and Integrity Constraints (2).pptx (20)

Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)
 
Mysql
MysqlMysql
Mysql
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
 
Database testing
Database testingDatabase testing
Database testing
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
SQL2.pptx
SQL2.pptxSQL2.pptx
SQL2.pptx
 
Adbms
AdbmsAdbms
Adbms
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
 
Oracle 11g SQL Overview
Oracle 11g SQL OverviewOracle 11g SQL Overview
Oracle 11g SQL Overview
 
4.Database Management System.pdf
4.Database Management System.pdf4.Database Management System.pdf
4.Database Management System.pdf
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
12 SQL
12 SQL12 SQL
12 SQL
 
12 SQL
12 SQL12 SQL
12 SQL
 
Database programming
Database programmingDatabase programming
Database programming
 
lovely
lovelylovely
lovely
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 
Sql server
Sql serverSql server
Sql server
 
Dbms
DbmsDbms
Dbms
 
Ankit
AnkitAnkit
Ankit
 

Último

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Último (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

SQL and Integrity Constraints (2).pptx

  • 2. Concept of DDL, DML, DCL Structured Query Language(SQL) as we all know is the database language by the use of which we can perform certain operations on the existing database and also we can use this language to create a database. Sql uses certain commands like Create, Drop, Insert, etc.
  • 3.
  • 4. DDL – Data Definition Language Data Definition Language actually consists of the SQL commands that can be used to define the database schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in the database.DDL is a set of SQL commands used to create, modify, and delete database structures but not data. These commands are normally not used by a general user, who should be accessing the database via an application.
  • 5. ● CREATE: This command is used to create the database or its objects (like table, index, function, views, store procedure, and triggers). ● DROP: This command is used to delete objects from the database. ● ALTER: This is used to alter the structure of the database. ● TRUNCATE: This is used to remove all records from a table, including all spaces allocated for the records are removed. ● COMMENT: This is used to add comments to the data dictionary. ● RENAME: This is used to rename an object existing in the database.
  • 6. DQL (Data Query Language) DQL statements are used for performing queries on the data within schema objects. The purpose of the DQL Command is to get some schema relation based on the query passed to it. We can define DQL as follows it is a component of SQL statement that allows getting data from the database and imposing order upon it. It includes the SELECT statement. This command allows getting the data out of the database to perform operations with it. When a SELECT is fired against a table or tables the result is compiled into a further temporary table, which is displayed or perhaps received by the program i.e. a front-end.
  • 7. ● SELECT: It is used to retrieve data from the database.
  • 8. DML(Data Manipulation Language) DML or Data Manipulation Language and this includes most of the SQL statements. It is the component of the SQL statement that controls access to data and to the database. Basically, DCL statements are grouped with DML statements
  • 9. ● INSERT: It is used to insert data into a table. ● UPDATE: It is used to update existing data within a table. ● DELETE : It is used to delete records from a database table. ● LOCK: Table control concurrency. ● CALL: Call a PL/SQL or JAVA subprogram. ● EXPLAIN PLAN: It describes the access path to data.
  • 10. DCL (Data Control Language) DCL includes commands such as GRANT and REVOKE which mainly deal with the rights, permissions, and other controls of the database system. ● GRANT:This command gives users access privileges to the database. ● REVOKE: This command withdraws the user’s access privileges given by using the GRANT command.
  • 12. ● Applications: – It can be considered as a user-friendly web page where the user enters the requests. Here he simply... ● End User: – They are the real users of the database. They can be developers, designers, administrators, or the actual... ● DDL: – Data Definition Language (DDL) is a query fired to create database, schema, tables, mappings, etc in the database. ● DDL Compiler: – This part of the database is responsible for processing the DDL commands. That means this compiler...
  • 13. Set operations Union Union combines two different results obtained by a query into a single result in the form of a table. However, the results should be similar if union is to be applied on them. Syntex: Select Student_Name from Art_Students UNION Select Student_Name from Dance_Students
  • 14. Intersection The intersection operator gives the common data values between the two data sets that are intersected. The two data sets that are intersected should be similar for the intersection operator to work. Intersection also removes all duplicates before displaying the result. Syntex: Select Student_Name from Art_Students INTERSECT Select Student_Name from Dance_Students
  • 16. COUNT FUNCTION ● COUNT function is used to Count the number of rows in a database table. It can work on both numeric and non- numeric data types. ● COUNT function uses the COUNT(*) that returns the count of all the rows in a specified table. COUNT(*) considers duplicate and Null. Syntax 1. COUNT(*) 2. or 3. COUNT( [ALL|DISTINCT] expression )
  • 17. SUM Function Sum function is used to calculate the sum of all selected columns. It works on numeric fields only. Syntax 1. SUM() 2. or 3. SUM( [ALL|DISTINCT] expression )
  • 18. AVG function The AVG function is used to calculate the average value of the numeric type. AVG function returns the average of all non-Null values. Syntax 1. AVG() 2. or 3. AVG( [ALL|DISTINCT] expression )
  • 19. MAX Function MAX function is used to find the maximum value of a certain column. This function determines the largest value of all selected values of a column. Syntax MAX() 1. or 2. MAX( [ALL|DISTINCT] expression )
  • 20. MIN Function MIN function is used to find the minimum value of a certain column. This function determines the smallest value of all selected values of a column. Syntax 1. MIN() 2. or 3. MIN( [ALL|DISTINCT] expression )
  • 21. Domain constraints in DBMS ● Domain constraints ● Entity Integrity constraints ● Referential Integrity constraints ● Key constraints
  • 22. Domain Constraints Domain Constraints are user-defined columns that help the user to enter the value according to the data type. And if it encounters a wrong input it gives the message to the user that the column is not fulfilled properly. Or in other words, it is an attribute that specifies all the possible values that the attribute can hold like integer, character, date, time, string, etc.
  • 23. Domain Constraints – Not Null: Null values are the values that are unassigned or we can also say that which are unknown or the missing attribute values and by default, a column can hold the null values. Create table employee (employee_id varchar(30), employee_name varchar(30) not null, salary NUMBER);
  • 24. Domain Constraints – Check: It defines a condition that each row must satisfy which means it restricts the value of a column between ranges or we can say that it is just like a condition or filter checking before saving data into a column. It ensures that when a tuple is inserted inside the relation must satisfy the predicate given in the check clause. Create table employee (employee_id varchar(30) not null check(employee_id > 0), employee_name varchar(30), salary NUMBER);
  • 26. Domain constraints ● Domain constraints can be defined as the definition of a valid set of values for an attribute. ● The data type of domain includes string, character, integer, time, date, currency, etc. The value of the attribute must be available in the corresponding domain.
  • 27. Entity integrity constraints ● The entity integrity constraint states that primary key value can't be null. ● This is because the primary key value is used to identify individual rows in relation and if the primary key has a null value, then we can't identify those rows. ● A table can contain a null value other than the primary key field.
  • 28. Referential Integrity Constraints ● A referential integrity constraint is specified between two tables. ● In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary Key of Table 2, then every value of the Foreign Key in Table 1 must be null or be available in Table 2.
  • 29. Key constraints ● Keys are the entity set that is used to identify an entity within its entity set uniquely. ● An entity set can have multiple keys, but out of which one key will be the primary key. A primary key can contain a unique and null value in the relational table.