Top Banner
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 3 What is a Database System? e.g., Access, MySQL, Oracle, and MS SQL Server
34

What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Aug 06, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

3

Wh

at i

s a

Dat

abas

e S

yst

em?

e.g.,

Acc

ess,

M

yS

QL

, O

racl

e, a

nd

MS

SQ

L S

erver

Page 2: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

4

Dat

abas

e A

pp

lica

tio

n S

yst

ems

Page 3: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

5

Rat

ional

Dat

abas

e an

d R

elat

ional

Dat

a M

od

el

Most

of

today

’s d

atab

ase

syst

ems

are

rela

tional

dat

abas

e

syst

ems,

bas

ed o

n t

he

rela

tional

dat

a m

odel

. A r

elat

ional

dat

a

model

has

thre

e key

A r

elat

ional

dat

a m

odel

has

thre

e key

com

ponen

ts:

stru

cture

, in

tegri

ty a

nd l

anguag

es.

�Str

uct

ure

def

ines

the

repre

senta

tion o

f th

e dat

a.

�In

tegri

tyim

pose

s co

nst

rain

ts o

n t

he

dat

a.

�L

anguage

pro

vid

es t

he

mea

ns

for

acce

ssin

g a

nd

man

ipula

ting d

ata.

Page 4: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

6

Rel

atio

nal

Str

uct

ure

A r

elat

ion

al d

atab

ase

con

sist

s o

f a

set

of

rela

tio

ns.

A r

elat

ion

has

tw

o t

hin

gs

in o

ne:

a

sch

em

aan

d a

n i

nst

an

ce

of

the

sch

ema.

Th

e

sch

ema

def

ines

th

e re

lati

on

an

d a

n i

nst

ance

is

the

con

ten

t o

f th

e re

lati

on

at

a g

iven

tim

e. A

n

inst

ance

of

a re

lati

on

is

no

thin

g m

ore

th

an a

tab

le w

ith

ro

ws

and

nam

ed c

olu

mn

s. F

or

con

ven

ience

wit

h n

o c

on

fusi

on, w

e re

fer

inst

ance

s o

f re

lati

on

s as

ju

st r

ela

tio

ns

or

tab

les.

Page 5: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

7

Cou

rse

Tab

le

Page 6: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

8

Stu

den

t T

able

Page 7: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

9

En

roll

men

t

Tab

le

Page 8: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

10

Tab

le v

s. F

ile

NO

TE

:

A t

able

or

a re

lati

on i

s not

sam

e as

a f

ile.

Most

of

the

rela

tional

dat

abas

e sy

stem

s

store

mult

iple

tab

les

in a

fil

e.

Page 9: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

11

Inte

gri

ty C

on

stra

ints

An

in

teg

rity

co

nst

rain

t im

po

ses

a co

nd

itio

n t

hat

all

leg

al i

nst

ance

s o

f th

e re

lati

on

s m

ust

sat

isfy

. I

n

gen

eral

, th

ere

are

thre

e ty

pes

of

con

stra

ints

: d

om

ain

co

nst

rain

t, p

rim

ary

key c

on

stra

int,

an

d f

ore

ign

key

co

nst

rain

t. D

om

ain

co

nst

rain

ts a

nd

pri

mar

y k

ey

con

stra

ints

are

kn

ow

n a

s in

tra

-rela

tio

nal

co

nst

rain

ts, m

ean

ing

th

at a

co

nst

rain

t in

vo

lves

on

ly

on

e re

lati

on

. T

he

fore

ign

key

co

nst

rain

t is

kn

ow

n

as i

nte

r-re

lati

onal,

mea

nin

g t

hat

a c

on

stra

int

inv

olv

es m

ore

th

an o

ne

rela

tio

n.

Page 10: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

12

Dom

ain

Con

stra

ints

Page 11: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

13

Pri

mar

y K

ey C

onst

rain

ts

courseId subjectId courseNumber title numOfCredits

11111 CSCI 1301 Introduction to Java I 4

11112 CSCI 1302 Introduction to Java II 3

11113 CSCI 3720 Database Systems 3

...

ssn courseId dateRegistered grade

444111110 11111 2004-03-19 A

444111110 11112 2004-03-19 B

444111110 11113 2004-03-19 C

...

Cou

rse

Tab

le

Eac

h v

alu

e in

th

e

nu

mO

fCre

dit

s co

lum

n m

ust

be

gre

ater

th

an 0

and

les

s th

an 5

Eac

h v

alu

e in

cou

rseI

d i

n t

he

En

roll

men

t ta

ble

mu

st m

atch

a v

alu

e

in c

ou

rseI

d i

n t

he

Cou

rse

tab

le

Eac

h r

ow

mu

st h

ave

a

val

ue

for

cou

serI

d,

and

the

val

ue

mu

st b

e u

niq

ue

En

roll

men

t T

able

Pri

ma

ry k

ey

con

stra

int

Page 12: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

14

Fore

ign

Key

Co

nst

rain

ts

courseId subjectId courseNumber title numOfCredits

11111 CSCI 1301 Introduction to Java I 4

11112 CSCI 1302 Introduction to Java II 3

11113 CSCI 3720 Database Systems 3

...

ssn courseId dateRegistered grade

444111110 11111 2004-03-19 A

444111110 11112 2004-03-19 B

444111110 11113 2004-03-19 C

...

Cou

rse

Tab

le

Eac

h v

alu

e in

th

e

nu

mO

fCre

dit

s co

lum

n m

ust

be

gre

ater

th

an 0

and

les

s th

an 5

Eac

h v

alu

e in

cou

rseI

d i

n t

he

En

roll

men

t ta

ble

mu

st m

atch

a v

alu

e

in c

ou

rseI

d i

n t

he

Cou

rse

tab

le

Eac

h r

ow

mu

st h

ave

a

val

ue

for

cou

serI

d,

and

the

val

ue

mu

st b

e u

niq

ue

En

roll

men

t T

able

Fo

reig

n k

ey

con

stra

int

Page 13: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

15

Dom

ain

Con

stra

ints

Do

ma

in c

on

stra

ints

spec

ify

th

e p

erm

issi

ble

val

ues

for

an a

ttri

bu

te. D

om

ain

s ca

n b

e sp

ecif

ied

usi

ng

stan

dar

d d

ata

typ

es s

uch

as

inte

ger

s, f

loat

ing

-poin

t

nu

mb

ers,

fix

ed-l

ength

str

ing

s, a

nd

var

ian

t-le

ngth

stri

ng

s. T

he

stan

dar

d d

ata

typ

e sp

ecif

ies

a b

road

ran

ge

of

val

ues

. Ad

dit

ion

al c

on

stra

ints

can

be

spec

ifie

d t

o n

arro

w t

he

ran

ges

. Y

ou

can

als

o s

pec

ify

wh

eth

er a

n a

ttri

bu

te c

an b

e n

ull

.

Page 14: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

16

Dom

ain

Con

stra

ints

Exam

ple

);

crea

te t

ab

leC

ou

rse

(

cou

rseI

d c

ha

r(5

),

sub

ject

Id c

ha

r(4

) n

ot

nu

ll,

cou

rseN

um

ber

in

teg

er,

titl

e v

arc

ha

r(5

0)

no

t n

ull

,

nu

mO

fCre

dit

s in

teg

er,

con

stra

int

gre

ate

rTh

an

On

e

chec

k (

nu

mO

fCre

dit

s >

= 1

));

Page 15: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

17

Su

per

key

Su

per

key

Key

Can

did

ate

key

Pri

mar

y

key

A s

up

erk

ey i

s an

att

rib

ute

or

a se

t o

f at

trib

ute

s

that

un

iqu

ely

id

enti

fy t

he

rela

tio

n. T

hat

is,

no

two

tu

ple

s h

ave

the

sam

e v

alu

es o

n t

he

sup

erk

ey.

By

def

init

ion

, a

rela

tio

n c

on

sist

s o

f a

set

of

dis

tin

ct t

up

les.

Th

e se

t o

f al

l at

trib

ute

s in

th

e

rela

tio

n f

orm

s a

sup

erk

ey.

Page 16: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

18

Key

an

d C

and

idat

e K

eyS

uper

key

Key

Can

did

ate

key

Pri

mar

y

key

A k

eyK

is

a m

inim

al s

up

erk

ey, m

ean

ing

th

at a

ny

pro

per

su

bse

t o

f K

is

no

t a

sup

erk

ey. It

is

po

ssib

le t

hat

a r

elat

ion

has

sev

eral

key

s. I

n t

his

case

, ea

ch o

f th

e k

eys

is c

alle

d a

ca

nd

ida

te k

ey.

Page 17: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

19

Pri

mar

y K

ey

Super

key

Key

Can

did

ate

key

Pri

mar

y

key

Th

e p

rim

ary

key

is

on

e o

f th

e ca

nd

idat

e k

eys

des

ign

ated

by

th

e d

atab

ase

des

ign

er. T

he

pri

mar

y

key

is

oft

en u

sed

to

id

enti

fy t

up

les

in a

rel

atio

n.

crea

te t

able

Co

urs

e(

sub

ject

Co

de

char

(4),

cou

rseN

um

ber

in

t,

titl

e v

arch

ar(5

0),

nu

mO

fCre

dit

s in

t

con

stra

int

gre

ater

Than

One

chec

k (

nu

mO

fCre

dit

s >

= 1

),

pri

mar

y k

ey (

sub

ject

Co

de,

co

urs

eNum

ber

));

Page 18: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

20

Pri

mar

y K

eyT

he

pri

ma

ryk

ey i

s o

ne

of

the

can

did

ate

key

s d

esig

nat

ed b

y

the

dat

abas

e d

esig

ner

. T

he

pri

mar

y k

ey i

s o

ften

use

d t

o

iden

tify

tu

ple

s in

a r

elat

ion

.

crea

te t

ab

leC

ou

rse

(

cou

rseI

d c

ha

r(5

),

sub

ject

Id c

ha

r(4

) n

ot

nu

ll,

cou

rseN

um

ber

in

teg

er,

titl

e v

arc

ha

r(5

0)

no

t n

ull

,

nu

mO

fCre

dit

s in

teg

er,

pri

ma

ry k

ey(c

ou

rseI

d)

);

Page 19: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

21

Pri

mar

y K

ey C

onst

rain

ts

Th

e p

rim

ary

key

co

nst

rain

tsp

ecif

ies

that

th

e p

rim

ary

key

val

ue

of

a tu

ple

can

no

t b

e n

ull

an

d n

o t

wo

tu

ple

s in

th

e

rela

tio

n c

an h

ave

the

sam

e v

alu

e o

n t

he

pri

mar

y k

ey. T

he

DB

MS

en

forc

es t

he

pri

mar

y k

ey c

on

stra

int.

Fo

r ex

amp

le,

if

yo

u a

ttem

pt

to i

nse

rt a

rec

ord

wit

h t

he

sam

e p

rim

ary

key

as

an e

xis

tin

g r

eco

rd i

n t

he

tab

le, th

e D

BM

S w

ou

ld r

epo

rt a

n

erro

r an

d r

ejec

t th

e o

per

atio

n.

Page 20: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

22

Fore

ign

Key

Co

nst

rain

ts

In a

rel

atio

nal

dat

abas

e, d

ata

are

rela

ted

. T

up

les

in a

rela

tio

n a

re r

elat

ed a

nd

tu

ple

s in

dif

fere

nt

rela

tio

ns

are

rela

ted

th

rou

gh

th

eir

com

mo

n a

ttri

bu

tes.

Info

rmal

ly s

pea

kin

g, th

e co

mm

on

att

rib

ute

s ar

e

fore

ign

key

s. T

he

fore

ign

key c

on

stra

ints

def

ine

the

rela

tio

nsh

ips

amo

ng

rel

atio

ns.

Page 21: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

23

Fore

ign K

ey C

onst

rain

ts F

orm

al

Def

init

ion

Fo

rmal

ly, a

set

of

attr

ibu

tes

FK

is a

fo

reig

n k

ey

in a

rela

tio

n R

that

ref

eren

ces

rela

tio

n T

if i

t sa

tisf

ies

the

foll

ow

ing t

wo

ru

les:

�T

he

attr

ibu

tes

in F

Kh

ave

the

sam

e d

om

ain

as

the

pri

mar

y k

ey i

n T

.

�A

no

n-n

ull

val

ue

on

FK

in R

mu

st m

atch

a

pri

mar

y k

ey v

alu

e in

T.

R

T

F

K

Page 22: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

24

Fore

ign K

ey E

xam

ple

create table Enrollment (

ssn char(9),

courseId char(5),

dateRegistered date,

grade char(1),

primary key (ssn, courseId),

foreign key (ssn) references Student,

foreign key (courseId) references Course

);

Page 23: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

25

Fore

ign

Key

Dis

cuss

ion

A f

ore

ign

key

is

no

t n

eces

sari

ly t

he

pri

mar

y k

ey o

r p

art

of

the

pri

mar

y i

n t

he

rela

tio

n. F

or

exam

ple

, su

bje

ctC

od

e

is a

fo

reig

n k

ey i

n t

he

Co

urs

eta

ble

th

at r

efer

ence

s th

e

Su

bje

ctta

ble

, b

ut

it i

s n

ot

the

pri

mar

y k

ey i

n C

ou

rse.

dep

artm

entC

od

eis

a f

ore

ign

key

in

th

e S

ub

ject

tab

le

that

ref

eren

ces

Dep

artm

ent,

bu

t it

is

no

t th

e p

rim

ary

key

in S

ub

ject

.

Page 24: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

26

Fore

ign K

ey D

iscu

ssio

n,

cont.

Th

e re

fere

nci

ng r

elat

ion

an

d t

he

refe

ren

ced

rela

tio

n m

ay b

e th

e sa

me

tab

le. F

or

exam

ple

,

sup

erv

iso

rId

is a

fo

reig

n k

ey i

n F

acu

lty

that

refe

ren

ces

facu

lty

Idin

Fac

ult

y.

Page 25: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

27

Fore

ign K

ey D

iscu

ssio

n,

cont.

Th

e fo

reig

n k

ey i

s n

ot

nec

essa

ry t

o h

ave

the

sam

e n

ame

as i

ts r

efer

ence

d p

rim

ary

key

as

lon

g

as t

hey

hav

e th

e sa

me

do

mai

n. F

or

exam

ple

,

hea

dId

is a

fo

reig

n k

ey i

n D

epar

tmen

tth

at

refe

ren

ces

facu

lty

Idin

Fac

ult

y.

Page 26: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

28

Fore

ign K

ey D

iscu

ssio

n,

cont.

A r

elat

ion

may

hav

e m

ore

th

an o

ne

fore

ign k

ey.

Fo

r ex

amp

le, h

ead

Idan

d c

oll

egeC

ode

are

bo

th

fore

ign

key

s in

Dep

artm

ent.

Page 27: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

29

SQ

L

Str

uct

ure

d Q

uer

y L

ang

uag

e, p

ron

ou

nce

d S

-Q-L

, o

r S

equ

el

To

acc

ess

or

wri

te a

pp

lica

tio

ns

for

dat

abas

e sy

stem

s, y

ou

nee

d

to u

se t

he

Str

uct

ure

d Q

uer

y L

ang

uag

e (S

QL

). S

QL

is

the

un

iver

sal

lan

gu

age

for

acce

ssin

g r

elat

ion

al d

atab

ase

syst

ems.

Ap

pli

cati

on

pro

gra

ms

may

all

ow

use

rs t

o a

cces

s d

atab

ase

wit

ho

ut

dir

ectl

y u

sin

g S

QL

, b

ut

thes

e ap

pli

cati

on

s th

emse

lves

mu

st u

se S

QL

to

acc

ess

the

dat

abas

e.

Page 28: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

30

Ex

amp

les

of

sim

ple

SQ

L s

tate

men

ts

Cre

ate

tab

le

Dro

p t

able

Des

crib

e ta

ble

Sel

ect

Inse

rt

Del

ete

Up

dat

e

crea

te t

able

Co

urs

e (

cou

rseI

d c

har

(5),

sub

ject

Id c

har

(4)

no

t n

ull

,

cou

rseN

um

ber

in

teg

er,

titl

e v

arch

ar(5

0)

no

t n

ull

,

nu

mO

fCre

dit

s in

teg

er,

pri

mar

y k

ey (

cou

rseI

d)

);

crea

te t

able

Stu

den

t (

ssn

ch

ar(9

),

firs

tNam

e v

arch

ar(2

5),

m

i ch

ar(1

),

last

Nam

e v

arch

ar(2

5),

b

irth

Dat

e d

ate,

st

reet

var

char

(25),

p

ho

ne

char

(11),

zi

pC

od

e ch

ar(5

),d

eptI

d c

har

(4),

p

rim

ary k

ey (

ssn

)

);

Page 29: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

31

Ex

amp

les

of

sim

ple

SQ

L s

tate

men

ts

Cre

ate

tab

le

Dro

p t

able

Des

crib

e ta

ble

Sel

ect

Inse

rt

Del

ete

Up

dat

e

dro

p t

able

En

roll

men

t;

dro

p t

able

Co

urs

e;

dro

p t

able

Stu

den

t;

Page 30: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

32

Ex

amp

les

of

sim

ple

SQ

L s

tate

men

ts

Cre

ate

tab

le

Dro

p t

able

Des

crib

e ta

ble

Sel

ect

Inse

rt

Del

ete

Up

dat

e

des

crib

e C

ou

rse;

--

Ora

cle

Page 31: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

33

Ex

amp

les

of

sim

ple

SQ

L s

tate

men

ts

Cre

ate

tab

le

Dro

p t

able

Des

crib

e ta

ble

Sel

ect

Inse

rt

Del

ete

Up

dat

e

sele

ct f

irst

Nam

e, m

i, l

astN

ame

fro

m S

tud

ent

wh

ere

dep

tId

= 'C

S';

sele

ct f

irst

Nam

e, m

i, l

astN

ame

fro

m S

tud

ent

wh

ere

dep

tId

= 'C

S' a

nd

zip

Co

de

= '3

14

11

';

sele

ct *

fro

m S

tud

ent

wh

ere

dep

tId

= 'C

S' a

nd

zip

Co

de

= '3

14

11

';

Page 32: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

34

Ex

amp

les

of

sim

ple

SQ

L s

tate

men

ts

Cre

ate

tab

le

Dro

p t

able

Des

crib

e ta

ble

Sel

ect

Inse

rt

Del

ete

Up

dat

e

inse

rt i

nto

Co

urs

e (c

ou

rseI

d, su

bje

ctId

, co

urs

eNu

mb

er, ti

tle)

val

ues

('1

111

3',

'CS

CI'

, '3

72

0',

'Dat

abas

e S

yst

ems'

, 3

);

Page 33: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

35

Ex

amp

les

of

sim

ple

SQ

L s

tate

men

ts

Cre

ate

tab

le

Dro

p t

able

Des

crib

e ta

ble

Sel

ect

Inse

rt

Up

dat

e

Del

ete

up

dat

e C

ou

rse

set

nu

mO

fCre

dit

s =

4

wh

ere

titl

e =

'Dat

abas

e S

yst

ems'

;

Page 34: What is a Database System? - Cleveland State Universitycis.csuohio.edu/~sschung/cis430/32slideDatabaseOnly.pdf · To access or write applications for database system s, you need to

Lia

ng, In

troduction to J

ava P

rogra

mm

ing, N

inth

Editio

n,

(c)

2013 P

ears

on E

ducation, In

c. A

ll

rights

reserv

ed.

36

Ex

amp

les

of

sim

ple

SQ

L s

tate

men

ts

Cre

ate

tab

le

Dro

p t

able

Des

crib

e ta

ble

Sel

ect

Inse

rt

Up

dat

e

Del

ete

del

ete

Co

urs

e

wh

ere

titl

e =

'Dat

abas

e S

yst

em';