Documente Academic
Documente Profesional
Documente Cultură
Chapter 8
SQL-99: Schema
Definition, Basic
Constraints, and Queries
The database users must still enter a value for the new
attribute JOB for each EMPLOYEE tuple. This can be
done using the UPDATE command.
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-7
Features Added in SQL2 and
SQL-99
CREATE SCHEMA
REFERENTIAL INTEGRITY
OPTIONS
EMPLOYEE.LNAME, DEPARTMENT.DNAME
– In Q8, the alternate relation names E and S are called aliases or tuple
variables for the EMPLOYEE relation
– We can think of E and S as two different copies of EMPLOYEE; E
represents employees in role of supervisees and S represents
employees in role of supervisors
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-22
ALIASES (cont.)
– Aliasing can also be used in any SQL query for convenience
Can also use the AS keyword to specify aliases
Q1C: SELECT *
FROM EMPLOYEE
WHERE DNO=5
Q1D: SELECT *
FROM EMPLOYEE, DEPARTMENT
WHERE DNAME='Research' AND
DNO=DNUMBER
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-26
USE OF DISTINCT
SQL does not treat a relation as a set; duplicate tuples can
appear
To eliminate duplicate tuples in a query result, the
keyword DISTINCT is used
For example, the result of Q11 may have duplicate
SALARY values whereas Q11A does not have any
duplicate values
or as:
– In this case, the grouping and functions are applied after the joining of
the two relations
The LIKE operator allows us to get around the fact that each
value is considered atomic and indivisible; hence, in SQL,
character string attribute values are not atomic
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Slide 8-55
ARITHMETIC OPERATIONS
The standard arithmetic operators '+', '-'. '*', and '/' (for addition,
subtraction, multiplication, and division, respectively) can be
applied to numeric values in an SQL query result
Query 27: Show the effect of giving all employees who work
on the 'ProductX' project a 10% raise.