SlideShare a Scribd company logo
1 of 51
DBMS (UNIT 3)
BY:SURBHI SAROHA
SYLLABUS
• Query language: Relational Algebra
• Characteristics and various operations
• SQL
• Characteristics of SQL
• SQL data types and literals
• Concept of Data definition language
Cont….
• Data manipulation language
• Data Control language: Basic Structure
• Set operations
• Aggregate Functions
• Null Values
• Views
• Nested Sub-queries
Query language: Relational Algebra
• Relational algebra refers to a procedural query language that takes relation
instances as input and returns relation instances as output.
• It performs queries with the help of operators.
• A binary or unary operator can be used.
• They take in relations as input and produce relations as output.
• Recursive relational algebra is applied to a relationship, and intermediate
outcomes are also considered relations.
The following are the fundamental operations
present in a relational algebra:
• Select Operation
• Project Operation
• Union Operation
• Set Different Operation
• Cartesian Product Operation
• Rename Operation
Select Operation (or σ)
• It selects tuples from a relation that satisfy the provided predicate.
• The notation is − σp(r)
• Here σ stands for the selection predicate while r stands for the relation. p refers to
the prepositional logic formula that may use connectors such as or, and, and not.
Also, these terms may make use of relational operators such as − =, ≠, ≥, < , >, ≤.
• Example
• σsubject = “information”(Novels)
• The output would be − Selecting tuples from the novels wherever the subject
happens to be ‘information’.
Project Operation (or ∏)
• It projects those column(s) that satisfy any given predicate.
• Here B1, B2 , An refer to the attribute names of the relation r.
• The notation is − ∏B1, B2, Bn (r)
• Remember that duplicate rows are eliminated automatically, since relation is a set.
• Example
• ∏subject, writer (Novels)
• The output would be − Selecting and projecting columns named as writer as well
as the subject from the relation Novels.
Union Operation (or ∪)
• It would perform binary union between two relations.
• The notation is − r U s
• It is defined as follows:
• r ∪ s = { t | t ∈ r or t ∈ s}
• Here r and s either refer to DB relations or the relation result set (or temporary
relation).
• The given conditions must hold if we want any union operation to be valid:
• s, and r must contain a similar number of attributes.
CONT…..
• The domains of an attribute must be compatible.
• The duplicate tuples are eliminated automatically.
• ∏ writer (Novels) ∪ ∏ writer (Articles)
• The output would be − Projecting the names of those writers who might
have written either an article or a novel or both.
Set Different Operation (or −)
• Tuples refers to the result of the set difference operation. These are present
in just one of the relations but not at all in the second one.
• The notation is − r − s
• Finding all the tuples present in r and not present in s.
• ∏ writer (Novels) − ∏ writer (Articles)
• The output would be − Providing the writer names who might have
written novels but have not written articles.
Cartesian Product Operation (or Χ)
• It helps in combining data and info of two differing relations into a single one.
• The notation is − r Χ s
• Where s and r refer to the relations. Their outputs would be defined as the follows:
• s Χ r = { t ∈ s and q t | q ∈ r}
• σwriter = ‘mahesh'(Novels Χ Articles)
• The output would be − Yielding a relation that shows all the articles and novels
written by mahesh.
Rename Operation (or ρ)
• Relations are the results of the relational algebra, but without any name.
Thus, the rename operation would allow us to rename the relation output.
The ‘rename’ operation is basically denoted by the small Greek
letter ρ or rho.
• The notation is − ρ x (E)
• Here the result of the E expression is saved with the name of x.
Characteristics and various operations
Characteristics and various operations
• The relational algebra is a theoretical procedural query language which takes an instance of
relations and does operations that work on one or more relations to describe another
relation without altering the original relation(s). Thus, both the operands and the outputs are
relations. So the output from one operation can turn into the input to another operation,
which allows expressions to be nested in the relational algebra, just as you nest arithmetic
operations. This property is called closure: relations are closed under the algebra, just as
numbers are closed under arithmetic operations.
• The relational algebra is a relation-at-a-time (or set) language where all tuples are controlled
in one statement without the use of a loop. There are several variations of syntax for
relational algebra commands, and you use a common symbolic notation for the commands
and present it informally.
SQL
• SQL stands for Structured Query Language
• SQL lets you access and manipulate databases
• SQL became a standard of the American National Standards Institute
(ANSI) in 1986, and of the International Organization for Standardization
(ISO) in 1987
What Can SQL do?
• SQL can execute queries against a database
• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
• SQL can create new databases
• SQL can create new tables in a database
• SQL can create stored procedures in a database
• SQL can create views in a database
• SQL can set permissions on tables, procedures, and views
Characteristics of SQL
• The ANSI SQL provides with:
• Specific syntax and semantics of SQL data definition and data manipulation languages.
• It also provides with basic data structure and operations for designing, assessing, maintaining, controlling and
protecting SQL databases.
• Portability of database definition and application is also provided. Applications can be moved from one
machine to another.
• IS professionals share a common language and reduce training costs.
• Professionals can become proficient in its use and increase the productivity.
• It provides with longevity.
• It provides with reduced dependence on single vendor.
Rules to write commands:
• Table names cannot exceed 20 characters.
• Name of the table must be unique.
• Field names also must be unique.
• The field list and filed length must be enclosed in parentheses.
• The user must specify the field length and type.
• The field definitions must be separated with commas.
• SQL statements must end with a semicolon.
SQL data types and literals
• SQL data types define the type of value that can be stored in a table column. For example,
if you want a column to store only integer values, you can define its data type as INT.
• SQL data types can be broadly divided into the following categories.
• Numeric data types such as: INT, TINYINT, BIGINT, FLOAT, REAL, etc.
• Date and Time data types such as: DATE, TIME, DATETIME, etc.
• Character and String data types such as: CHAR, VARCHAR, TEXT, etc.
• Unicode character string data types such as: NCHAR, NVARCHAR, NTEXT, etc.
• Binary data types such as: BINARY, VARBINARY, etc.
• Miscellaneous data types - CLOB, BLOB, XML, CURSOR, TABLE, etc.
Concept of Data definition language
• A data definition language (DDL) is a computer language used to create and modify the
structure of database objects in a database.
• These database objects include views, schemas, tables, indexes, etc.
• The present database industry incorporates DDL into any formal language describing data.
• However, it is considered to be a subset of SQL (Structured Query Language).
• SQL often uses imperative verbs with normal English such as sentences to implement
database modifications.
• Hence, DDL does not show up as a different language in an SQL database, but does define
changes in the database schema.
CONT…..
• It is used to establish and modify the structure of objects in a database by
dealing with descriptions of the database schema. Unlike data manipulation
language (DML) commands that are used for data modification purposes,
DDL commands are used for altering the database structure such as creating
new tables or objects along with all their attributes (data type, table name,
etc.).
• Commonly used DDL in SQL querying are CREATE, ALTER, DROP, and
TRUNCATE.
Data manipulation language
• A DML (data manipulation language) refers to a computer programming
language that allows you to add (insert), delete (delete), and alter (update)
data in a database.
• A DML is typically a sublanguage of a larger database language like SQL,
with the DML containing some of the language’s operators. A DML (data
manipulation language) is a group of computer languages that provide
commands for manipulating data in databases.
Data Control language: Basic Structure
• DCL includes commands such as GRANT and REVOKE which mainly deal with
the rights, permissions, and other controls of the database system.
• List of DCL commands:
• GRANT: This command gives users access privileges to the database.
• Syntax:
• GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER,
ANOTHER_USER;
Cont…..
• REVOKE: This command withdraws the user’s access privileges given by
using the GRANT command.
• Syntax:REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1,
USER2;
Set operations
• Set operators in MySQL allow you to manage and compare data sets. Data from one or
more tables or queries can be combined, intersected, or subtracted using them.
• The three most frequently utilized set operators are UNION, INTERSECT, and EXCEPT.
• A single result set is created by combining the output of two or more SELECT operations
using UNION.
• INTERSECT returns the rows shared by the result sets of two SELECT statements.
• The rows that are specific to the first SELECT statement and absent from the
second SELECT statement are returned by EXCEPT.
UNION Operator
• The UNION operator is one of the most often-used set operators in MySQL. It
combines the results of two or more SELECT operations into a single result set.
• The syntax for using the UNION operator is as follows:
• SELECT column1, column2, ...
• FROM table1
• UNION
• SELECT column1, column2, ...
• FROM table2
Cont….
• SELECT name FROM employees
• UNION
• SELECT name FROM customers;
Union All
• Union All operation is equal to the Union operation.
• It returns the set without removing duplication and sorting the data.
• SELECT column_name FROM table1
• UNION ALL
• SELECT column_name FROM table2;
Cont….
• SELECT * FROM First
• UNION ALL
• SELECT * FROM Second;
3. Intersect
• It is used to combine two SELECT statements. The Intersect operation
returns the common rows from both the SELECT statements.
• In the Intersect operation, the number of datatype and columns must be the
same.
• It has no duplicates and it arranges the data in ascending order by default.
Cont….
• SELECT column_name FROM table1
• INTERSECT
• SELECT column_name FROM table2;
Minus
• It combines the result of two SELECT statements.
• Minus operator is used to display the rows which are present in the first
query but absent in the second query.
• It has no duplicates and data arranged in ascending order by default.
• SELECT column_name FROM table1
• MINUS
• SELECT column_name FROM table2;
Aggregate Functions
Aggregate Functions
• In database management an aggregate function is a function where the values of multiple
rows are grouped together as input on certain criteria to form a single value of more
significant meaning.
• Various Aggregate Functions
• 1) Count()
• 2) Sum()
• 3) Avg()
• 4) Min()
• 5) Max()
Now let us understand each Aggregate function
with a example:
• Id Name Salary
• -----------------------
• 1 A 80
• 2 B 40
• 3 C 60
• 4 D 70
• 5 E 60
• 6 F Null
Count():
• Count(*): Returns total number of records .i.e 6.
Count(salary): Return number of Non Null values over the column salary.
i.e 5.
Count(Distinct Salary): Return number of distinct Non Null values over
the column salary .i.e 4
• Sum():
• sum(salary): Sum all Non Null values of Column salary i.e., 310
• sum(Distinct salary): Sum of all distinct Non-Null values i.e., 250.
Cont….
• Avg():
•
• Avg(salary) = Sum(salary) / count(salary) = 310/5
Avg(Distinct salary) = sum(Distinct salary) / Count(Distinct Salary) = 250/4
•
• Min():
•
• Min(salary): Minimum value in the salary column except NULL i.e., 40.
Max(salary): Maximum value in the salary i.e., 80.
Null Values
• A field with a NULL value is a field with no value.
• If a field in a table is optional, it is possible to insert a new record or update
a record without adding a value to this field.
• Then, the field will be saved with a NULL value.
• SELECT column_names
FROM table_name
WHERE column_name IS NULL;
Views
• In SQL, a view is a virtual table based on the result-set of an SQL statement.
• A view contains rows and columns, just like a real table. The fields in a view
are fields from one or more real tables in the database.
• You can add SQL statements and functions to a view and present the data as
if the data were coming from one single table.
• A view is created with the CREATE VIEW statement.
Cont….
• CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
• CREATE VIEW [Brazil Customers] AS
• SELECT CustomerName, ContactName
• FROM Customers
• WHERE Country = 'Brazil';
Nested Sub-queries
• A Subquery or Inner query or a Nested query is a query within another SQL
query and embedded within clauses, most commonly in the WHERE clause.
It is used to return data from a table, and this data will be used in the main
query as a condition to further restrict the data to be retrieved.
• Subqueries can be used with the SELECT, INSERT, UPDATE, and
DELETE statements along with the operators like =, <, >, >=, <=, IN,
BETWEEN, etc.
There are a few rules that subqueries must
follow −
• Subqueries must be enclosed within parentheses.
• A subquery can have only one column in the SELECT clause, unless multiple
columns are in the main query for the subquery to compare its selected columns.
• An ORDER BY command cannot be used in a subquery, although the main query
can use an ORDER BY. The GROUP BY command can be used to perform the
same function as the ORDER BY in a subquery.
• Subqueries that return more than one row can only be used with multiple value
operators such as the IN operator.
Cont…
• The SELECT list cannot include any references to values that evaluate to a
BLOB, ARRAY, CLOB, or NCLOB.
• A subquery cannot be immediately enclosed in a set function.
• The BETWEEN operator cannot be used with a subquery. However, the
BETWEEN operator can be used within the subquery.
Subqueries with the SELECT Statement
• SELECT column_name [, column_name ]
• FROM table1 [, table2 ]
• WHERE column_name OPERATOR
• (SELECT column_name [, column_name ]
• FROM table1 [, table2 ]
• [WHERE])
Cont…
• SELECT *
• FROM CUSTOMERS
• WHERE ID IN (SELECT ID
• FROM CUSTOMERS
• WHERE SALARY > 4500) ;
Subqueries with the INSERT Statement
• INSERT INTO table_name [ (column1 [, column2 ]) ]
• SELECT [ *|column1 [, column2 ]
• FROM table1 [, table2 ]
• [ WHERE VALUE OPERATOR ]
Cont…..
• INSERT INTO CUSTOMERS_BKP
• SELECT * FROM CUSTOMERS
• WHERE ID IN (SELECT ID
• FROM CUSTOMERS) ;
Subqueries with the UPDATE Statement
• UPDATE CUSTOMERS
• SET SALARY = SALARY * 0.25
• WHERE AGE IN (SELECT AGE FROM CUSTOMERS_BKP
• WHERE AGE >= 27 );
Subqueries with the DELETE Statement
• DELETE FROM CUSTOMERS
• WHERE AGE IN (SELECT AGE FROM CUSTOMERS_BKP
• WHERE AGE >= 27 );
THANK YOU

More Related Content

Similar to DBMS UNIT 3

Query Decomposition and data localization
Query Decomposition and data localization Query Decomposition and data localization
Query Decomposition and data localization Hafiz faiz
 
Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Rakibul Hasan Pranto
 
Big data analytics with R tool.pptx
Big data analytics with R tool.pptxBig data analytics with R tool.pptx
Big data analytics with R tool.pptxsalutiontechnology
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusChhom Karath
 
Unit I Database concepts - RDBMS & ORACLE
Unit I  Database concepts - RDBMS & ORACLEUnit I  Database concepts - RDBMS & ORACLE
Unit I Database concepts - RDBMS & ORACLEDrkhanchanaR
 
Introduction to R _IMPORTANT FOR DATA ANALYTICS
Introduction to R _IMPORTANT FOR DATA ANALYTICSIntroduction to R _IMPORTANT FOR DATA ANALYTICS
Introduction to R _IMPORTANT FOR DATA ANALYTICSHaritikaChhatwal1
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slidesenosislearningcom
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.pptMARasheed3
 
Data Analytics with R and SQL Server
Data Analytics with R and SQL ServerData Analytics with R and SQL Server
Data Analytics with R and SQL ServerStéphane Fréchette
 
Python programming
Python programmingPython programming
Python programmingSwetha544947
 
SQL Queries
SQL QueriesSQL Queries
SQL QueriesNilt1234
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptxSheethal Aji Mani
 
Relational data model
Relational data modelRelational data model
Relational data modelSURBHI SAROHA
 

Similar to DBMS UNIT 3 (20)

Query Decomposition and data localization
Query Decomposition and data localization Query Decomposition and data localization
Query Decomposition and data localization
 
Relational model
Relational modelRelational model
Relational model
 
Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)
 
Unit 4 plsql
Unit 4  plsqlUnit 4  plsql
Unit 4 plsql
 
Big data analytics with R tool.pptx
Big data analytics with R tool.pptxBig data analytics with R tool.pptx
Big data analytics with R tool.pptx
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*Plus
 
PostgreSQL - Case Study
PostgreSQL - Case StudyPostgreSQL - Case Study
PostgreSQL - Case Study
 
Unit I Database concepts - RDBMS & ORACLE
Unit I  Database concepts - RDBMS & ORACLEUnit I  Database concepts - RDBMS & ORACLE
Unit I Database concepts - RDBMS & ORACLE
 
Introduction to R _IMPORTANT FOR DATA ANALYTICS
Introduction to R _IMPORTANT FOR DATA ANALYTICSIntroduction to R _IMPORTANT FOR DATA ANALYTICS
Introduction to R _IMPORTANT FOR DATA ANALYTICS
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slides
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
 
Module02
Module02Module02
Module02
 
Data Analytics with R and SQL Server
Data Analytics with R and SQL ServerData Analytics with R and SQL Server
Data Analytics with R and SQL Server
 
Python programming
Python programmingPython programming
Python programming
 
SQL 3.pptx
SQL 3.pptxSQL 3.pptx
SQL 3.pptx
 
12 SQL
12 SQL12 SQL
12 SQL
 
12 SQL
12 SQL12 SQL
12 SQL
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
Relational data model
Relational data modelRelational data model
Relational data model
 

More from SURBHI SAROHA

Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptxSURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxSURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxSURBHI SAROHA
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)SURBHI SAROHA
 

More from SURBHI SAROHA (20)

Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
 
DBMS (UNIT 5)
DBMS (UNIT 5)DBMS (UNIT 5)
DBMS (UNIT 5)
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
 
DBMS (UNIT 2)
DBMS (UNIT 2)DBMS (UNIT 2)
DBMS (UNIT 2)
 
JAVA UNIT 2
JAVA UNIT 2JAVA UNIT 2
JAVA UNIT 2
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
 

Recently uploaded

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 

DBMS UNIT 3

  • 2. SYLLABUS • Query language: Relational Algebra • Characteristics and various operations • SQL • Characteristics of SQL • SQL data types and literals • Concept of Data definition language
  • 3. Cont…. • Data manipulation language • Data Control language: Basic Structure • Set operations • Aggregate Functions • Null Values • Views • Nested Sub-queries
  • 4. Query language: Relational Algebra • Relational algebra refers to a procedural query language that takes relation instances as input and returns relation instances as output. • It performs queries with the help of operators. • A binary or unary operator can be used. • They take in relations as input and produce relations as output. • Recursive relational algebra is applied to a relationship, and intermediate outcomes are also considered relations.
  • 5. The following are the fundamental operations present in a relational algebra: • Select Operation • Project Operation • Union Operation • Set Different Operation • Cartesian Product Operation • Rename Operation
  • 6. Select Operation (or σ) • It selects tuples from a relation that satisfy the provided predicate. • The notation is − σp(r) • Here σ stands for the selection predicate while r stands for the relation. p refers to the prepositional logic formula that may use connectors such as or, and, and not. Also, these terms may make use of relational operators such as − =, ≠, ≥, < , >, ≤. • Example • σsubject = “information”(Novels) • The output would be − Selecting tuples from the novels wherever the subject happens to be ‘information’.
  • 7. Project Operation (or ∏) • It projects those column(s) that satisfy any given predicate. • Here B1, B2 , An refer to the attribute names of the relation r. • The notation is − ∏B1, B2, Bn (r) • Remember that duplicate rows are eliminated automatically, since relation is a set. • Example • ∏subject, writer (Novels) • The output would be − Selecting and projecting columns named as writer as well as the subject from the relation Novels.
  • 8. Union Operation (or ∪) • It would perform binary union between two relations. • The notation is − r U s • It is defined as follows: • r ∪ s = { t | t ∈ r or t ∈ s} • Here r and s either refer to DB relations or the relation result set (or temporary relation). • The given conditions must hold if we want any union operation to be valid: • s, and r must contain a similar number of attributes.
  • 9. CONT….. • The domains of an attribute must be compatible. • The duplicate tuples are eliminated automatically. • ∏ writer (Novels) ∪ ∏ writer (Articles) • The output would be − Projecting the names of those writers who might have written either an article or a novel or both.
  • 10. Set Different Operation (or −) • Tuples refers to the result of the set difference operation. These are present in just one of the relations but not at all in the second one. • The notation is − r − s • Finding all the tuples present in r and not present in s. • ∏ writer (Novels) − ∏ writer (Articles) • The output would be − Providing the writer names who might have written novels but have not written articles.
  • 11. Cartesian Product Operation (or Χ) • It helps in combining data and info of two differing relations into a single one. • The notation is − r Χ s • Where s and r refer to the relations. Their outputs would be defined as the follows: • s Χ r = { t ∈ s and q t | q ∈ r} • σwriter = ‘mahesh'(Novels Χ Articles) • The output would be − Yielding a relation that shows all the articles and novels written by mahesh.
  • 12. Rename Operation (or ρ) • Relations are the results of the relational algebra, but without any name. Thus, the rename operation would allow us to rename the relation output. The ‘rename’ operation is basically denoted by the small Greek letter ρ or rho. • The notation is − ρ x (E) • Here the result of the E expression is saved with the name of x.
  • 14. Characteristics and various operations • The relational algebra is a theoretical procedural query language which takes an instance of relations and does operations that work on one or more relations to describe another relation without altering the original relation(s). Thus, both the operands and the outputs are relations. So the output from one operation can turn into the input to another operation, which allows expressions to be nested in the relational algebra, just as you nest arithmetic operations. This property is called closure: relations are closed under the algebra, just as numbers are closed under arithmetic operations. • The relational algebra is a relation-at-a-time (or set) language where all tuples are controlled in one statement without the use of a loop. There are several variations of syntax for relational algebra commands, and you use a common symbolic notation for the commands and present it informally.
  • 15. SQL • SQL stands for Structured Query Language • SQL lets you access and manipulate databases • SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987
  • 16. What Can SQL do? • SQL can execute queries against a database • SQL can retrieve data from a database • SQL can insert records in a database • SQL can update records in a database • SQL can delete records from a database • SQL can create new databases • SQL can create new tables in a database • SQL can create stored procedures in a database • SQL can create views in a database • SQL can set permissions on tables, procedures, and views
  • 17. Characteristics of SQL • The ANSI SQL provides with: • Specific syntax and semantics of SQL data definition and data manipulation languages. • It also provides with basic data structure and operations for designing, assessing, maintaining, controlling and protecting SQL databases. • Portability of database definition and application is also provided. Applications can be moved from one machine to another. • IS professionals share a common language and reduce training costs. • Professionals can become proficient in its use and increase the productivity. • It provides with longevity. • It provides with reduced dependence on single vendor.
  • 18. Rules to write commands: • Table names cannot exceed 20 characters. • Name of the table must be unique. • Field names also must be unique. • The field list and filed length must be enclosed in parentheses. • The user must specify the field length and type. • The field definitions must be separated with commas. • SQL statements must end with a semicolon.
  • 19. SQL data types and literals • SQL data types define the type of value that can be stored in a table column. For example, if you want a column to store only integer values, you can define its data type as INT. • SQL data types can be broadly divided into the following categories. • Numeric data types such as: INT, TINYINT, BIGINT, FLOAT, REAL, etc. • Date and Time data types such as: DATE, TIME, DATETIME, etc. • Character and String data types such as: CHAR, VARCHAR, TEXT, etc. • Unicode character string data types such as: NCHAR, NVARCHAR, NTEXT, etc. • Binary data types such as: BINARY, VARBINARY, etc. • Miscellaneous data types - CLOB, BLOB, XML, CURSOR, TABLE, etc.
  • 20. Concept of Data definition language • A data definition language (DDL) is a computer language used to create and modify the structure of database objects in a database. • These database objects include views, schemas, tables, indexes, etc. • The present database industry incorporates DDL into any formal language describing data. • However, it is considered to be a subset of SQL (Structured Query Language). • SQL often uses imperative verbs with normal English such as sentences to implement database modifications. • Hence, DDL does not show up as a different language in an SQL database, but does define changes in the database schema.
  • 21. CONT….. • It is used to establish and modify the structure of objects in a database by dealing with descriptions of the database schema. Unlike data manipulation language (DML) commands that are used for data modification purposes, DDL commands are used for altering the database structure such as creating new tables or objects along with all their attributes (data type, table name, etc.). • Commonly used DDL in SQL querying are CREATE, ALTER, DROP, and TRUNCATE.
  • 22. Data manipulation language • A DML (data manipulation language) refers to a computer programming language that allows you to add (insert), delete (delete), and alter (update) data in a database. • A DML is typically a sublanguage of a larger database language like SQL, with the DML containing some of the language’s operators. A DML (data manipulation language) is a group of computer languages that provide commands for manipulating data in databases.
  • 23.
  • 24. Data Control language: Basic Structure • DCL includes commands such as GRANT and REVOKE which mainly deal with the rights, permissions, and other controls of the database system. • List of DCL commands: • GRANT: This command gives users access privileges to the database. • Syntax: • GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;
  • 25. Cont….. • REVOKE: This command withdraws the user’s access privileges given by using the GRANT command. • Syntax:REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;
  • 26. Set operations • Set operators in MySQL allow you to manage and compare data sets. Data from one or more tables or queries can be combined, intersected, or subtracted using them. • The three most frequently utilized set operators are UNION, INTERSECT, and EXCEPT. • A single result set is created by combining the output of two or more SELECT operations using UNION. • INTERSECT returns the rows shared by the result sets of two SELECT statements. • The rows that are specific to the first SELECT statement and absent from the second SELECT statement are returned by EXCEPT.
  • 27. UNION Operator • The UNION operator is one of the most often-used set operators in MySQL. It combines the results of two or more SELECT operations into a single result set. • The syntax for using the UNION operator is as follows: • SELECT column1, column2, ... • FROM table1 • UNION • SELECT column1, column2, ... • FROM table2
  • 28. Cont…. • SELECT name FROM employees • UNION • SELECT name FROM customers;
  • 29. Union All • Union All operation is equal to the Union operation. • It returns the set without removing duplication and sorting the data. • SELECT column_name FROM table1 • UNION ALL • SELECT column_name FROM table2;
  • 30. Cont…. • SELECT * FROM First • UNION ALL • SELECT * FROM Second;
  • 31. 3. Intersect • It is used to combine two SELECT statements. The Intersect operation returns the common rows from both the SELECT statements. • In the Intersect operation, the number of datatype and columns must be the same. • It has no duplicates and it arranges the data in ascending order by default.
  • 32. Cont…. • SELECT column_name FROM table1 • INTERSECT • SELECT column_name FROM table2;
  • 33. Minus • It combines the result of two SELECT statements. • Minus operator is used to display the rows which are present in the first query but absent in the second query. • It has no duplicates and data arranged in ascending order by default. • SELECT column_name FROM table1 • MINUS • SELECT column_name FROM table2;
  • 35. Aggregate Functions • In database management an aggregate function is a function where the values of multiple rows are grouped together as input on certain criteria to form a single value of more significant meaning. • Various Aggregate Functions • 1) Count() • 2) Sum() • 3) Avg() • 4) Min() • 5) Max()
  • 36. Now let us understand each Aggregate function with a example: • Id Name Salary • ----------------------- • 1 A 80 • 2 B 40 • 3 C 60 • 4 D 70 • 5 E 60 • 6 F Null
  • 37. Count(): • Count(*): Returns total number of records .i.e 6. Count(salary): Return number of Non Null values over the column salary. i.e 5. Count(Distinct Salary): Return number of distinct Non Null values over the column salary .i.e 4 • Sum(): • sum(salary): Sum all Non Null values of Column salary i.e., 310 • sum(Distinct salary): Sum of all distinct Non-Null values i.e., 250.
  • 38. Cont…. • Avg(): • • Avg(salary) = Sum(salary) / count(salary) = 310/5 Avg(Distinct salary) = sum(Distinct salary) / Count(Distinct Salary) = 250/4 • • Min(): • • Min(salary): Minimum value in the salary column except NULL i.e., 40. Max(salary): Maximum value in the salary i.e., 80.
  • 39. Null Values • A field with a NULL value is a field with no value. • If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. • Then, the field will be saved with a NULL value. • SELECT column_names FROM table_name WHERE column_name IS NULL;
  • 40. Views • In SQL, a view is a virtual table based on the result-set of an SQL statement. • A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database. • You can add SQL statements and functions to a view and present the data as if the data were coming from one single table. • A view is created with the CREATE VIEW statement.
  • 41. Cont…. • CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition; • CREATE VIEW [Brazil Customers] AS • SELECT CustomerName, ContactName • FROM Customers • WHERE Country = 'Brazil';
  • 42. Nested Sub-queries • A Subquery or Inner query or a Nested query is a query within another SQL query and embedded within clauses, most commonly in the WHERE clause. It is used to return data from a table, and this data will be used in the main query as a condition to further restrict the data to be retrieved. • Subqueries can be used with the SELECT, INSERT, UPDATE, and DELETE statements along with the operators like =, <, >, >=, <=, IN, BETWEEN, etc.
  • 43. There are a few rules that subqueries must follow − • Subqueries must be enclosed within parentheses. • A subquery can have only one column in the SELECT clause, unless multiple columns are in the main query for the subquery to compare its selected columns. • An ORDER BY command cannot be used in a subquery, although the main query can use an ORDER BY. The GROUP BY command can be used to perform the same function as the ORDER BY in a subquery. • Subqueries that return more than one row can only be used with multiple value operators such as the IN operator.
  • 44. Cont… • The SELECT list cannot include any references to values that evaluate to a BLOB, ARRAY, CLOB, or NCLOB. • A subquery cannot be immediately enclosed in a set function. • The BETWEEN operator cannot be used with a subquery. However, the BETWEEN operator can be used within the subquery.
  • 45. Subqueries with the SELECT Statement • SELECT column_name [, column_name ] • FROM table1 [, table2 ] • WHERE column_name OPERATOR • (SELECT column_name [, column_name ] • FROM table1 [, table2 ] • [WHERE])
  • 46. Cont… • SELECT * • FROM CUSTOMERS • WHERE ID IN (SELECT ID • FROM CUSTOMERS • WHERE SALARY > 4500) ;
  • 47. Subqueries with the INSERT Statement • INSERT INTO table_name [ (column1 [, column2 ]) ] • SELECT [ *|column1 [, column2 ] • FROM table1 [, table2 ] • [ WHERE VALUE OPERATOR ]
  • 48. Cont….. • INSERT INTO CUSTOMERS_BKP • SELECT * FROM CUSTOMERS • WHERE ID IN (SELECT ID • FROM CUSTOMERS) ;
  • 49. Subqueries with the UPDATE Statement • UPDATE CUSTOMERS • SET SALARY = SALARY * 0.25 • WHERE AGE IN (SELECT AGE FROM CUSTOMERS_BKP • WHERE AGE >= 27 );
  • 50. Subqueries with the DELETE Statement • DELETE FROM CUSTOMERS • WHERE AGE IN (SELECT AGE FROM CUSTOMERS_BKP • WHERE AGE >= 27 );