DBMS Chapter7 Notes
DBMS Chapter7 Notes
Data Definition Language : It is a transaction control language (TCL). The DML commands
in SQL are executed within the context of a transaction, which is a logical unit of work
composed of one or more SQL statements, as defined by business rules
It is a data control language (DCL). Data control commands are used to control
access to data objects, such as giving one user permission only to view the
PRODUCT table and giving another user permission to change the data in the
PRODUCT table.
DDL : CREATE TABLE, NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY,
DEFAULT, CHECK, CREATE INDEX, CREATE VIEW, ALTER TABLE
TCL : COMMIT, ROLLBACK
DCL: GRANT, REVOKE
Data Types
There are three fundamental types of data: character data, numeric data, and date data.
- Character data is also often referred to as a “string” because it is a collection of
characters threaded together to create the value.
- Numeric data is composed of digits, such that the data has a specific numeric value.
- Date datais composed of date and, occasionally, time values.
- Although character data may contain digits, such as a phone number or Social
Security number, the DBMS does not recognize the numeric value of those digits.
Special Operators :
- Between : : Used to check whether an attribute value is within a range
- IN: Used to check whether an attribute value matches any value within a
value list
- LIKE: Used to check whether an attribute value matches any value within a
value list
% means any and all following or preceding characters are eligible. For example:
_ means any one character may be substituted for the underscore. For example:
Natural Join : You are not limited to two tables when performing a natural join
Determines the common attribute(s) by looking for attributes with identical names
and compatible data types.
Selects only the rows with common values in the common attribute(s).
If there are no common attributes, returns the relational product of the two tables.
JOIN USING
The query returns only the rows with matching values in the column indicated in the USING
clause—and that column must exist in both tables. The syntax is:
JOIN ON
The query returns only the rows that meet the indicated join condition. The join condition
typically includes an equality comparison expression of two columns. (The columns may or
may not share the same name, but obviously they must have comparable data types.) The
syntax is:
OUTER JOIN
An outer join returns not only the rows matching the join condition (that is, rows
with matching values in the common columns), but also the rows with unmatched
values
Cross Join
A cross join performs a relational product (also known as the Cartesian product) of two
tables. The cross join syntax is:
The use of the ALL operator allows you to compare a single value (P_QOH *
P_PRICE) with a list of values returned by the first subquery (sqA) using a
comparison operator other than equals.
The ANY operator allows you to compare a single value to a list of values and select
only the rows for which the inventory cost is greater than or less than any value in the
list. You could also use the equal to ANY operator, which would be the equivalent of
the IN operator.
a correlated subquery is a subquery that executes once for each row in the outer query. The
process is similar to the typical nested loop in a programming language. For example:
FOR X = 1 TO 2
FOR Y = 1 TO 3
PRINT "X = "X, "Y = "Y
END
END
X=1 Y=1
X=1 Y=2
X=1 Y=3
X=2 Y=1
X=2 Y=2
X=2 Y=3
Correlated subqueries can also be used with the EXISTS special operator