Вы находитесь на странице: 1из 3

Structured Query Language

SQL
 Originally developed in the System-R
project of IBM (1974)
 Industry standard for relational
databases (SQL92 is an
ANSI/ISO standard)

Structured Query Language SQL - Data Definition Language

 Data Definition Language for defining  Create table


relations, views, integrity -
constraints, triggers Integrity
Constraints (next
lecture) 
 Data Manipulation Language for Delete Table
updating, and querying 

 Database Control Language for defining Alter Table


acces rights, concurrency control,
etc….

SQL DDL, creation (simple) Integrity Constraints - Primary Key


CREATE TABLE relation-name
 Primary Key is a set of attributes which
(attribute-name domain
[, attribute-name domain ]*)
identifies uniquely a tuple (i.e., a row in a
table)
CREATE -E.g., your NRIC or your email address
TABLE branch varchar(10)
-The combination (name, city) in the branch table
,  You cannot have two tuples with the same
( name city varchar(20)
director , Primary Key in a table
assets number)
varchar(20)
, -E.g., there cannot be two persons with the same
branch director assets NRIC. There cannot be two branches with the
city
name
same name in the same city

1
SQL DML,
DDL, creation
insertionexample
(query) SQL DML,Reference
SQL DDL, deletion to other table
INSERT INTO relation_name [(Att [,Att]*)] query DELETE
CREATE FROM
TABLE relation_name [WHERE qualification]
workfor
CREATE TABLE branch ( branch_name varchar(10) ,
Example: INSERT( INTO
namejohor_director (we assume such a table was created)
varchar(10), city varchar(20),
Example: DELETE FROM branch
city SELECTvarchar(20),
director employee varchar(20)
WHERE city = ‘Jakarta’ andREFERENCES staff(name) )
assets < 1000000
director FROM varchar(20),
branch WHERE city = ‘Johor Barhu’ workforbranch
branch assets number, branch_name city employee staff
name city PRIMARY KEY (name,
director city) )
assets
johor_director name city director assets
name Address Tel
Buona Vista Singapore Singapore
Clementi John Ng Wee Hiong 3000000
director
Clementi Singapore Ng Wee 3000000 Tom Addr1
Buona Vista Singapore Johor
F_branch Tom Barhu John 1500000 21223343
Hiong John
Clementi Singapore Tom
S_branch Johor Barhu George
John 1200000 61223367
Addr2
F_branch Johor John 1500000 George
Barhu Branch_one
name must be Jakarta
the Bo Helen
Lee Addr3 80000 97229343
S_branch Johor George 1200000 Agus Arianto
Barhu primary key Jakarta
Monas 4000000

of staff

SQL DML,
DDL, deletion
update SQL DML,
DDL, alteration
update example
branch name
ALTER TABLE city director
relation_name ADD Att Domain assets
Clementi Singapore Ng Wee Hiong 3000000
Example:F_branch
ALTER TABLE branch ADD zip INTEGER
Johor Barhu John 1500000
UPDATE relation_name
KL_branch Kuala Lumpur Yu Fei 1000000
SET att = expr
DROP TABLE
[WHERE relation_name
qualification] branch name city director assets zip
UPDATE branch
SET assets = assets * 1.5
Example: DROP TABLE branch WHERE city = ‘Kuala Lumpur’
ALTER TABLE relation_name DROP Att
branch
Example:name
ALTER TABLEcity director
branch DROP zip assets
Clementi Singapore Ng Wee Hiong 3000000
F_branch Johor Barhu John 1500000
branch name
KL_branch
city director
Kuala Lumpur
assets
Yu Fei 1500000

SQL DML, simple query SQL


SQL DML, DML,
simple query insertion
example
(values) INSERT INTO relation_name [(Att
SQL - Data [,Att]*)] VALUES (value [,value]*)
SELECT *
Manipulation INSERT INTO branchFROM work_for
(name, director, city, assets)
[DISTINCT] target-list
Language
SELECT
FROM
 Insert
relation-list VALUES (‘Clementi’, ‘Ng Wee Hiong’, ‘Singapore’,
3000000)
 Delete
name branch_name
work_for city employee
Example: [WHERE qualification]

Update  Queries city director assets Clementi Kuala Lumpur Yu Fei

-Simple Clementi Singapore Ng Wee Hiong


-Advanced queries (Aggregations, etc.)
Selections branch Clementi
Clementi
Singapore
Singapore
Peter Ho
Ng Wee Hiong 3000000
Clementi Singapore Jean Do
-Nested Queries
Monas Jakarta Agus Arianto
-Views Monas Jakarta Reza Santi

32

Вам также может понравиться