0% found this document useful (0 votes)
4 views

DBMS Chapter7 Notes

Chapter 7 notes

Uploaded by

nainularab999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

DBMS Chapter7 Notes

Chapter 7 notes

Uploaded by

nainularab999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL

 SQL is a nonprocedural language: you merely command what is to be done; you do


not have to worry about how.

Data Manipulation Commands : It is a data definition language (DDL). SQL includes


commands to create database objects such as tables, indexes, and views, as well as commands
to define access rights to those database objects.
SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY ,INSERT, UPDATE,
DELETE, Comparison operators, Logical Operators

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.

- Data retrieval is done in SQL using a SELECT query.


- Most SQL data manipulation commands operate over an entire table (relation), which
is why SQL commands are said to be set-orientedcommands. A SQL set-
oriented command works over a set of rows
- The set may include one or more columns and zero or more rows from one or more
tables
- SELECT—specifies the attributes to be returned by the query
- FROM—specifies the table(s) from which the data will be
retrieved
- WHERE—filters the rows of data based on provided criteria
- GROUP BY—groups the rows of data into collections based on
sharing the same values in one or more attributes
- HAVING—filters the groups formed in the GROUP BY clause
based on provided criteria
- ORDER BY—sorts the final query result rows in ascending or
descending order based on the values of one or more
attributes.
- The columnlist represents one or more attributes, separated by
commas. If the programmer wants all of the columns to be
returned, then the asterisk (*) wildcard can be used.
A wildcard character is a symbol that can be used as a general
substitute for other characters or commands
- A computed column (also called a calculated column)
represents a derived attribute. A derived attribute may or may
not be stored in the database. If the decision is made not to
store the derived attribute, then the attribute must be
calculated when it is needed. For example, suppose that you
want to determine the total value of each product currently
held in inventory. Logically, that determination requires
multiplying each product’s quantity on hand by its current
price. You can accomplish this task with the following
command: select p_qoh*p_price from product

Arithmetic operators precedence rule


+ , -, *, /, ^

Order of computational sequence

1. Perform operations within parentheses.


2. Perform power operations.
3. Perform multiplications and divisions.
4. Perform additions and subtractions.

* Internally, the DBMS stores a date value in a numeric format.

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:

 'J%' includes Johnson, Jones, Jernigan, July, and J-231Q.

_ means any one character may be substituted for the underscore. For example:

 '_23-456-6789' includes 123-456-6789, 223-456-6789, and 323-456-6789.

- IS NULL : Used to check whether an attribute value is null

Natural Join : You are not limited to two tables when performing a natural join

The natural join performs the following tasks:

 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:

 SELECT column-list FROM table1 JOIN table2 USING (common-column)

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:

 SELECT column-list FROM table1 JOIN table2 ON join-condition

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:

 SELECT column-list FROM table1 CROSS JOIN table2

Aggregate Functions : Count, MIN, MAX, SUM, AVG


Multi row subquery operators ALL and ANY

SELECT P_CODE, P_QOH * P_PRICE AS TOTALVALUE


FROM PRODUCT
WHERE P_QOH * P_PRICE > ALL (SELECT P_QOH * P_PRICE
FROM PRODUCT
WHERE V_CODE IN (SELECT V_CODE
FROM VENDOR WHERE V_STATE = 'FL'));

 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

will yield the following output:

 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

Order of execution of query:


FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY

Transaction : A sequence of database requests that accesses the database. A


transaction is a logical unit of work; that is, it must be entirely completed or
aborted—no intermediate ending states are accepted. All transactions must have the
properties of atomicity, consistency, isolation, and durability.
Cascading order of sequence : A nested ordering sequence for a set of rows, such as
a list in which all last names are alphabetically ordered and, within the last names,
all first names are ordered.

You might also like