Dbms Module 3 Chapter 6
Dbms Module 3 Chapter 6
Dbms Module 3 Chapter 6
• The SELECT clause of SQL specifies the attributes whose values are to be retrieved, which
are called the projection attributes in relational algebra.
• The WHERE clause specifies the Boolean condition that must be true for any retrieved tuple,
which is known as the selection condition in relational algebra.
• Q1 Retrieve the name and address of all employees who work for the
‘Research’ department.
(0.1*E.Salary)+E.Salary
• Comparison operator BETWEEN
Query 14. Retrieve all employees in department 5 whose salary is
between $30,000 and $40,000.
Equivalent to the condition ((Salary >= 30000) AND (Salary <= 40000))
6.3.6 Ordering of Query Results
ORDER BY clause to order the tuples in the result of a query by the values of one
or more of the attributes that appear in the query result
• Query 15. Retrieve a list of employees and the projects they are working on,
ordered by department and, within each department, ordered alphabetically by
last name, then first name.
• We can specify the keyword DESC if we want to see the result in a descending
order of values. The keyword ASC can be used to specify ascending order
explicitly.
ORDER BY D.Dname DESC, E.Lname ASC, E.Fname ASC
Summary of Basic SQL Retrieval Queries
• A simple retrieval query in SQL can consist of up to four clauses, but
only the first two—SELECT and FROM—are mandatory.
• The clauses are specified in the following order, with the clauses
between square brackets [ … ] being optional:
• The clause WITH DATA specifies that the table will be created and
loaded with the data specified in the query.
• The DELETE command removes tuples from a relation.
• It includes a WHERE clause, to select the tuples to be deleted.
• Tuples are explicitly deleted from only one table at a time.
• The deletion may propagate to tuples in other relations if referential triggered
actions are specified in the referential integrity constraints of the DDL.
• Depending on the number of tuples selected by the condition in the WHERE
clause, zero, one, or several tuples can be deleted by a single DELETE command.
• A missing WHERE clause specifies that all tuples in the relation are to be
deleted; however, the table remains in the database as an empty table.
• We must use the DROP TABLE command to remove the table definition
6.4.3 The UPDATE Command
• The UPDATE command is used to modify attribute values of one or
more selected tuples.
• WHERE clause in the UPDATE command selects the tuples to be
modified from a single relation.
• Updating a primary key value may propagate to the foreign key values
of tuples in other relations if such a referential triggered action is
specified in the referential integrity constraints of the DDL.
• An additional SET clause in the UPDATE command specifies the
attributes to be modified and their new values.
• Several tuples can be modified with a single UPDATE command.