You are on page 1of 13

SQL

Introduction
Key Terms
• Data
– Any important information like an employee’s salary.
• Database
– An organized collection of data or information.
• DBMS
– Database Management System
– A Program that stores, retrieves, modifies data in
database.
• Relational database
– Collection of two-dimensional tables.
Relational Database Components
How a database is created?

Model of
Entity model of
system
client’s model
in client’s
mind
Table model
of entity model Oracle
server
Entity becomes a table
Attribute becomes columns of a table
Tables on disk
ER Diagram
– ER model consists of the various entities in a
business and the relationships among them.
EMPLOYEE assigned to DEPARTMENT
#* number #* number
* name * name
composed of
o job title o location
– Scenario:
• “. . . Assign one or more employees to a
department . . .”
• “. . . Some departments do not yet have assigned
employees….”
Relating Multiple Tables
– Each row of data in a table is uniquely identified by a
primary key.
– You can logically relate data from multiple tables
using foreign keys.
Table name: DEPARTMENTS

Table name: EMPLOYEES


Primary key Foreign key Primary key
Relational Database Terminology
3
2 4

1
Using SQL to Query Your
Database
• Structured query language (SQL) is:
– The ANSI standard language for operating
relational databases
– Efficient, easy to learn, and use
– Functionally complete (With SQL, you can define,
retrieve, and manipulate data in the tables.)
SELECT department_name
FROM departments;
Oracle
server
CreateReadUpdateDelete
Update:
Create: update xxx_temp
insert into xxx_temp
set id = 4
values (2, 'Test 2'); where id < 10
Read:
select id, text Delete:
from xxx_temp delete from xxx_temp
where id < 10 where id < 10
SQL Statements
SELECT
INSERT
UPDATE Data manipulation
DELETE language (DML)
MERGE
CREATE
ALTER
DROP Data definition language
RENAME (DDL)
TRUNCATE
COMMENT
GRANT Data control language (DCL)
REVOKE
COMMIT
ROLLBACK Transaction control
SAVEPOINT
Oracle 9i Components
(HR) Schema generally used for
training
LOCATIONS
DEPARTMENTS location_id
department_id street_address
department_name postal_code
manager_id city
location_id state_province
country_id

JOB_HISTORY
employee_id
start_date EMPLOYEES
end_date employee_id COUNTRIES
job_id first_name country_id
department_id last_name country_name
email region_id
phone_number
hire_date
job_id
salary
JOBS commission_pct
job_id manager_id
job_title REGIONS
department_id region_id
min_salary
max_salary region_name
Key Points For SQL Statements
• SQL statements are not case-sensitive. The data entered is
case sensitive.
• SQL statements can be entered on one or many lines.
• Keywords cannot be split across lines or abbreviated.
• Clauses are usually placed on separate lines for readability
and ease of editing.
• Indents should be used to make code more readable.
• Keywords typically are entered in uppercase; all other
words, such as table names and columns names are
entered in lowercase.
• Null is a value that is unavailable, unassigned, unknown, or
inapplicable. Null is not the same as zero or a blank space.
Zero is a number and blank space is a character.
• A literal is a character, a number, or a date that is included
in the SELECT statement.
• Date and character literal values must be enclosed within
single quotation marks.

You might also like