Week 3
Week 3
• Data-manipulation language (DML). The SQL DML provides the ability to query information from the
database and to insert tuples into, delete tuples from, and modify tuples in the database.
• Integrity. The SQL DDL includes commands for specifying integrity constraints that the data stored in
the database must satisfy. Updates that violate integrity constraints are disallowed.
• View definition. The SQL DDL includes commands for defining views.
• Embedded SQL and dynamic SQL. Embedded and dynamic SQL define how SQL statements can be
embedded within general-purpose programming languages, such as C, C++, and Java.
The SQL DDL allows specification of not only a set of relations, but also information about each relation, including:
d -
Q
⑭
③
③
..
-
Now consider another query, “Find the department names of all instructors,” which can be written as:
SQL allows us to use the keyword all to specify explicitly that duplicates are
not removed:
· T
The Natural Join
For example, suppose we wish to answer the query “List the names of instructors along with the the titles of courses that they teach.”
The query can be written in SQL as follows:
The Rename Operation
The names of the attributes in the result are derived from the names of the attributes in the relations in the from clause.
SQL provides a way of renaming the attributes of a result relation. It uses the as clause, taking the form:
String Operations
Set Comparison
As an example of the ability of a nested subquery to compare sets, consider the query “Find the names of all instructors
whose salary is greater than at least one instructor in the Biology department.”
Same
L
Let us find the names of all instructors that have a salary value greater than that of each instructor in the
Biology department. The construct > all corresponds to the phrase “greater than all.” Using this construct, we
write the query as follows:
.
The With Clause
Complex query for
with statement ,
-
·
An outer join in database management is a powerful technique used to combine data from two or more
tables. Unlike an inner join, which only returns rows when there’s a match in both tables, an outer join
retrieves both matched and unmatched rows from the tables involved in the query.
SQL Full Outer Join: In a full outer join, all rows from both tables are included. If there are
any unmatched rows, they appear with NULL values for the missing data.
SQL Left Outer Join: A left outer join returns all rows from the left table and matching rows
from the right table. If there’s no match in the right table, the result includes NULL values
for the right table’s columns.
SQL Right Outer Join: Similar to the left outer join, but it includes all rows from the right
table and matching rows from the left table.
A full outer join would include all rows from both tables, even if there’s no match. For example,
it would show both employees and their respective departments, filling in NULL values where
necessary.
A left outer join would include all employees and their departments (if available), but also
show NULL values for employees without a department.
A right outer join would include all departments and their associated employees (if available),
with NULL values for departments without employees.
Joined Relations
Equi Join
An Equi Join is a type of inner join used in SQL to combine data from two or more tables based on the equality
of specific columns. Here are the key points about Equi Joins
In an Equi Join, the comparison is made using the equals sign (=) as the comparison
operator.
It involves matching rows where specific columns have equal values.
If we perform an Equi Join on the AGENT_CODE column, the result would include data where the agent
codes match between the two tables.
Views
Integrity Constraints
Constraints on a Single Relation
Referential Integrity
Cascading Actions in Referential Integrity
User-Defined Types
Create Domains
Large-Object Types
Authorization
Privileges in SQL
SQL Functions
Structure
,
Returne
d table
SQL Procedures
Types of Triggers:
ingest
of temporarale
BEFORE
on
kind
-
AFTER
Row Level and Statement Level Triggers
Relational Algebra
Six Basic operators :-
SelectrowD
-
select-
Division operator :
Example >
-