Documente Academic
Documente Profesional
Documente Cultură
Chapter 4
1
Introduction to SQL
Nonprocedural language
American National Standards Institute (ANSI)
prescribes a standard SQL
10
First task:
- RDBMS creates physical files that will hold
database
- Tends to differ substantially from one RDBMS
to another
11
Authentication
- Process through which DBMS verifies that
only registered users are able to access
database
- Log on to RDBMS using user ID and
password created by database administrator
Schema
- Group of database objectssuch as tables
and indexesthat are related to each other
12
Data Types
13
14
16
SQL Constraints
UNIQUE constraint
- Ensures that all values in column are unique
DEFAULT constraint
- Assigns value to attribute when a new row is added to
table
CHECK constraint
- Validates data when attribute value is entered
17
SQL Indexes
indexes
can be created on basis of any selected attribute
Composite index
- Index based on two or more attributes
- Often used to prevent data duplication
18
19
INSERT
- Used to enter data into table
- Syntax:
21
Syntax:
- COMMIT [WORK];
SELECT
- Used to list contents of table
- Syntax:
SELECT columnlist
FROM tablename;
25
UPDATE
- Modify data in a table
- Syntax:
UPDATE tablename
SET columnname = expression [, columname =
expression]
[WHERE conditionlist];
ROLLBACK
- Used to restore database to its previous condition
- Only applicable if COMMIT command has not
been used to permanently store changes in
database
Syntax:
- ROLLBACK;
data
manipulation commands that are used to add,
modify, or delete table rows
27
DELETE
- Deletes a table row
- Syntax:
INSERT
- Inserts multiple rows from another table
(source)
- Uses SELECT subquery
- Syntax:
29
Syntax:
- SELECT columnlist
FROM tablelist
[ WHERE conditionlist ] ;
30
31
32
33
34
35
36
37
38
Arithmetic Operators:
The Rule of Precedence
40
Arithmetic Operators:
The Rule of Precedence (continued)
41
Logical Operators:
AND, OR, and NOT
42
Logical Operators:
AND, OR, and NOT (continued)
43
Logical Operators:
AND, OR, and NOT (continued)
44
Special Operators
BETWEEN
- Used to check whether attribute value is within
a range
IS NULL
- Used to check whether attribute value is null
LIKE
- Used to check whether attribute value
matches given string pattern
45
IN
- Used to check whether attribute value
matches any value within a value list
EXISTS
- Used to check if subquery returns any rows
46
ADD
MODIFY
DROP
47
48
49
Adding a Column
50
Dropping a Column
51
52
53
54
DROP
- Deletes table from database
- Syntax:
56
57
Ordering a Listing
58
59
60
61
Aggregate Functions
62
63
64
65
66
Grouping Data
67
68
69
70
71
73
74
75
76
Recursive Joins
77
78
Outer Joins
79
80
Summary
Summary (continued)
82
Summary (continued)
83
Summary (continued)
Aggregate functions
- Special functions that perform arithmetic
computations over a set of rows
ORDER BY clause
- Used to sort output of SELECT statement
- Can sort by one or more columns and use
either an ascending or descending order
Summary (continued)
85