0% found this document useful (0 votes)
149 views18 pages

Adobe Scan 19 Mar 2023 PDF

The document describes a sample relational database with three tables: Suppliers, Items, and Shipments. The Suppliers table contains supplier information like number, name, status, and location. The Items table contains item information like number, name, and price. The Shipments table links suppliers and items, showing the quantity supplied. Each table represents a relation, with rows representing tuples and columns representing attributes. Primary keys uniquely identify each tuple. The relational model organizes data into normalized tables to reduce redundancy and inconsistencies.

Uploaded by

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

Adobe Scan 19 Mar 2023 PDF

The document describes a sample relational database with three tables: Suppliers, Items, and Shipments. The Suppliers table contains supplier information like number, name, status, and location. The Items table contains item information like number, name, and price. The Shipments table links suppliers and items, showing the quantity supplied. Each table represents a relation, with rows representing tuples and columns representing attributes. Primary keys uniquely identify each tuple. The relational model organizes data into normalized tables to reduce redundancy and inconsistencies.

Uploaded by

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

Ill 502

data n
eeded for an org;:il'\:
. . . . l!Za_ij
F osMS of the rotected from damage I 0~,
11.2 PURPOSE O 0 silotJ and P . · t sh
b a rep private, t requirements can em.pl o
1 uld e tate, . nt da a d'ff oy tl
s)1sten1 s ,o Id be accl.1 ·th diffeie swill have i erent View i1
A database . ta shoU ·ons w1 end user soft
~
r-;::::;.:::;.::;;::.-
Processing. That dda' erse appJicall 11d diffcrent erall data
that n ers a ov
organized so . n rograinm coinrnon . the data
Dl·fierent applicaho ~ ,d (rotll a . searching A DBMS (D
i, denvc . g o1
hi
w c1 I must be t·
I ds o " ,,ccess1n M anagement Systeata
"tructure. Their met ,o . 1· c existing data a software that is r Ill) re
~ tti 1Z W storing, maintainin 0°1
esp
will differ. users want to t demands for ne 1

databases. A datgband o
The waJ'S in which end .l in some cases tly. The .extent . a ase
J gc onu d urgen . h with a DBMS is ref
will constantly c 1~n ;ise rapidly an. . d determines t e database systern. erred 1
uses of the data will a ~ n be sat1sf1e
. h . demands ca . . . .
to which t ese the database system- cords are stored m various files. Anull\
overall \"alue of in" system, permanent re tract records from and add records
In a hmical file-process t, • written to ex .
•Jr . ograms a1e b of maJor ,
different applicat10n pr . me has a num er 1. . • •.
approp
riate files. But this sche h data redundancy
. ta es sue as . f
lin ·tations and d1sadvan g ' . ( ultiple copies o
u d t ·nconststency m l
(duplication of data), a a 1 • other) unsharab e
chin with one an '
same data but not mat . g d t incorrect data etc. A
data, unstandardized data, i~secure at~ all these problems as
database management system ts answer h d t thereby
it provides a centralized control of t e a a, Mismatched multiple cop.e
minimizing these problems in the database. same data, is known as
Inconsistency.
11.3 RELATIONAL DATABASE MODEL

In relational data model, the data is organized into tables (i.e., rows and columns). Theseta
are called relations. A row in a table represents a relationship among a set of values. Sin~a
is a collection of such relationships, it is generally referred to using the mathematicaJ
relation, from which the relational data model derives its name.
Le_t us see how a sample database can be represented in relational form. The sample dal~
bemg shown here has three tables (relations) . Sup . It Sh . t
• p1zers, ems, ipmen s.
Suppliers (SuppNo, Supp Name St tu c·
a S, 1ty)
- I
Items (ItemNo Item_Name, Price)
Shipments (SuppNo, ItemNo Qty . 1]

Each of these three tables closely' _supplied) [coloured fields represent primanJ keythe 5
IJ~
. resembles of
correspondmg to records of the f'l1 a conventional sequential file with rows ca~1
th t bl · e and col ' ds P
ese a es is actually a special UJnns correspondin t fi Ids of the recor .. (JII
about relations and their ch ca~e of the construct kn . g o e . a re/atton•
aracteristics w own m mathematics as
Rows of relations are gene U ' e shall learn llnd ti ) ~1
attnbutes. ra y referred to .tu er sec on 11 .4 . f J
as pies anct the columns are usually re e
1. Primary-key is the key-field that can .
uniquely iden .
Britannia 10 DelN
S2 New Bakers 30 Mumbai
S3 Mother Dairy 10 Delhi
S4 Cnokz 50 Banplore
S5 l laldh-.1m '10 Jaipur

It-ems Sltipments

ltemNo

I1
ltem_Name

Milk
Price

15.00
- - SuppNo

S1
ltemNo

I2
Qty_supplied

10
20
12 Cake 5.00 S1 13

13 Bread 9.00 S1 16 20

14 Milk Bread 14.00 S2 14 20

15 Plain Biscuit 6.00 S2 15 10

16 Cream Biscuit 10.00 S3 11 10

17 Ice Cream 16.00 S3 17 10

18 Cold Drink 8.00 S4 18 30

19 Nam.keen 15.00 S5 19 30

Figure 11.1 Sample Database in Relational Form.

Notice, that here each supplier has a unique supplier number, exactly one name, status value
and location. Likewise, we assume that each item has a unique item number, name, price ; and
also that, at any given time, no more than one shipment exists for a given supplier/item
combination.

Components of a Table
Let us quickly have a look at various components of a table.
These are:
Byte A byte is a group of eight bits and is used to store a character.
Data Item A data item is the smallest unit of named data. It may consist of any number of bits or
(Field) bytes. A data item represents one type of information and is often referred to as a field or
data element
A record is a named collection of data items which represents a complete unit of
Record
information.
A table is a named collection of all occurrences of a given type of logical record.
Table
le
1 arg,'
rHtl 2uO! Jf]
LJlll{llllt
I h t N,111 ~1,111111
AllLll~A
~IN\ LI 1uunu
l ~ \,, 1111 IA i I(JI JtJ
\1NII A 2auuo
l ~ \' l•IIMAlt I' J( JI J( J
1,1'1 'll 11,(IIJIJ
l /\ 1 '
OHUl'I ~It
/\I H11 1/\
IlII J(JO
1uooo
N\. \0 l1INl \I I
till I I 00000
Nt ,, I,I IJOll
._ ANDI I I)
81 1111 20000
N ~J~J()( }()
1,\lM/\H
, Ul\l lA0I I
~/J{J(J()
2c,ooo
HWAMI R qulr
0"
ANf\ND
IOOOU iuoool=-~r--- 6 b1/(9
\II Nl,U I };W/\MI = =ID""-==
oOn aaouu 32000
w. 17 VIJf\~• UI IAI I \.
2
,,ooo
ANUJ '-.. ~111/\1 {MA 'I /000 00
\~ ..,9
\~ ~, \IANPAN/\ PAI IW/\ 1U000 180

-J-__,_~\. =-1- ~ l~oqulroo 4 byto


♦ Seo, prlmot) key flold 1,ns unlquu ~ Dnt11 ltom
1 v luo ror tlGCh row.

rigu1e 11.2 Co111po1w11h or a tablo.

In o table, each rl!cord i~ k\1.\nliri~d with ,1 uniqm\ vnhw i.e., in ., fit,ld of lablu, there arc uni~u
voluPs for oll records. This unlqul1 vuluc ichmlifitls lhc record. For i11sl.1no.? in Fig. l 1.2, lht..' fie!
Salc~manNumber h,1s uniqttl' v,ilu~i; for nil lhl~ r(1cords. Sn S.tll'SntanNumbcr is tlw prltlh • 11'
key here.

ln a ta.ble, u,~re may b: m01c lhnn rnw fil'ld having uniquP ,·,lhtt'S. ln such ,. c ..lsc, only onc 0
them 1:s declared as tJ1·1111ary k,•y. 1

Tlw rnlalional dt1l.1 modd is bnsL'd on O colle ·t,· 1 f l 1, . . . of th


(1~l.1ltonnl) dalabas~ sysh'm m,,y qtwry llwsc labl), . ,
• . 1.: t n o '"' 1cs (rd 1L1ons)
l ..
1 h~ user 11lc •

tuples, :md modify tuples. There ar~ sevl'ral 1, cs, 111f~nt l'\l'\W tuples (r('cord/row), c. er'/
such l:.rngu,1gcs are r~l.1tion,1\ qu~ry l(mgu,,, , ..111gu.J
..1gcs'-. or ~,nr n.'ssmg • lh CSl'\ opcr..ir1ons · '
, < gc Jnu l'l.'ltlhon"l ,11 "t'\br:1
Examples of common Rt_)l,1tional Dut iba, , ).t g '" · •
' ' st i, anag~m~nt S t ems include Oraclt' ,/ ,1 I ' 1,,,:.. ,
Micrnsoft SQl... Se,11er, MYSQL, lBM on 2 Jn11...- . . ys 1
S \p S l • IQ, •r n 1llJorm,x SAJ> .... - ,.,,r,st.
1
'
1 y ,a~e • tlro,lntci, PoshrreSQL' SQL.rte etc. ' ~yl>as,.• A,fo ,tfoe ~en,er 'Cut-e,,
~ 1 · ~
open-sour..._x, cnt<'q, St'
SQ It.? is a rcl<"'~,,:'lt l \i, taha&'.'
engine rcu'l~r ,, .." ''lb,,d, ,,d mh) th('\ 1'l(
database engin 0 .-is i . , . -4 ... J
'- ' ~l S('.... \'(h)\ h, S(' \\'1 .'\l\\ld~
-embedaed sy~tcab, \~--ud1 a~ .-.'\t"11.t"H 1~ pn(,tWs),
,
.~m,mg Mh('1-s
P0s+-greSQL .1 ~---c·"'I "ral
1s :. .
~ 0 t: purposl" anu ,,bJcct rt"lc1twna1 dM,'lh:,s<' )'\.'\ '\ ( ,
st 2
~o d"~~d open source database s) stern P0stg1·c~Ql 1s It('('., '\~ <)l'C '\ "-c)\
- :S source ...oae lS a"allable under PostgreSQl hcc1'l.sc, a hlwral ()}X'n S<)1m.<" ,"{'In\;\

Common database managemePt •ools for 'lr1ob1le de, 1cc~ 1( .. ~Qt Anya r tlH.2
Everywhere, IDA! Mobile Database, SQL Server Compact, SQt Server Compa t, ~Ql Ser&N-
E,.,-p1'e.ss, Oracle DatabaseLite, SQLite, SQLBase etc. Out of these SQt ite ls .a public Jom~m
Open Somce implementation.
There are some other database models namely network data model, hierarc idlJ
object oriented data model. But covering these here is beyond the scop~ of the book

11.4 THE RELATIONAL MODEL TERMINOLOGY


The relational model w as p ropounded by E.F. Codd of the m, t . md h.1:, :, nc~ ffi.'l'\fl
acknowledged as a very important concept in DBMS (Data Bas~ Managemei1.t $) , tc11,, )
technology. Let us explore this model in details. Different tenns used in th~ relational ll\<.'>-.1d ..we
being disrussed here.
Relation. In general, a relation is a table i.e., data arranged in rows and colum:1~ \ :rcl.., tfon lM:,
the follm"ling properties :
1. In any given column of a table, all items are of the same k.ind whereas lt('m, in Ji.~n.,.nt
columns may not be of the same kind.
2. For a row, each column must have an atomic (indh isible) v.,lue and al~o tor ,l ro\\ , a
column cannot have more than one value.
3. All rows of a relation are distinct. That is, a relation does not conlain tv. o rm, !"i whiah
are identical in every column. That is, each row of the rel.ltion c.m be uniqudy
identified by its contents.
!~'
4. There is no order maintained for rows inside a relation. !hat "e (\l1~~ot retrie, ~ ..my
thing by saying that from row number 5, column name 1s to L1e access~.
5. The columns 0 f a relation are assigned
distinct names and the ordering of these columt'\S
is immaterial.
Domain. A domain is a pool of values from which the actual A crucial feature of .relational
· in a oiven column are drawn. For example, data model is that ~ssoc,ations
values appearing tr
. g in the SuppNo column of both the
nn between rows are rtpresented
the values appea solely by data values n columns
. bl d the Shipments table are dra\\rn from the
Suppliers ta e an . "') arawn from a common doma,n.
. d · of all valid supplier numbers. (See Fig. lL:>.
underlying omam
thft 111wNo column n,o lfrowin
M, I OH1e1
vall1t1 rron1 tnip~II ,r num iorn llorno1n ,

91(1 ... SUPP. Namo Status


SCJPPNo
S1 Brltannlo '10
,o New Bakers
S2 30
20
s 13 S3 Mother Dairy 10
16 20
s S4 Cookz 50
14 20
~ S5 Haldiram 40
10 Jaipur
S2 15
10
ss 11
17 10
S3
S4 18 30
S5 19 30

figure 11.3 SuppNo in Suppliers and Shipments draw values from same domain.

In the sample database, observe that relations Suppliers and Shipments have a commond
supplier numbers domain) and so do Items and Shipments (Item numbers domain).
See that in the table Shipments the supplier S1 is supplying 10 units of item 12 and fro
table S11pplim it can be said that a Delhi based supplier Britannia is supplying 10 .
item 12. That is how the association between rows (S1, 12, 10 of Shipments and S1, Britann
Delhi of S.,,,,lim) can be represented.
Tuple.~ rows of tables (relations) are generally referred to as Tuples (usually pronoun
rhyme with u couples").
Attributes. The columns of tables ( la.
re tions) are generally referred to as attributes.
Degree. The number of atbibutes • . . Areli
having 3 attributes is said to be m _a relation determine the degree of a relatton, 'bu
said to be a relation of degree : ~~on of degree 3. Similarly, a relation having nattfl
said to be unary, relations o f ~ two ons ~f degree one are . . .:
degree three are ternary, ....., and rela:' binary, relations of d columns
n-ary. ons of degree n are The rows an as 1
known W
Cardinality The relation are pecti~
· number of tuples ( and Attributes r\u1es '
called the CIITdinality of the relation . rows) in a relation is number . of eadtt:,.,a~
Sldp,nnt, relation ii 9 Simi1ari
ttlation is 5 •
' e.g., the cardinality of
y, the card~l~-
relation ,s call ~n"a~'J'
f oWS I
• __ --111111ty of S,,,,,liers number O r rd.,.,,. /
known as Cl /
1tll I\ 1111 I 1 11) llt1
1 1111dll h111 I
I l 1 II ,•1111 1111 Ill 1111 I 11111 I I''
11,1•ll11d 1111,,1,h (1tl111i11111111,1y11111,,v1 1,,
1111 11l1l1 1h11 ,,1111lly1111i1,1l11d,1111 IIHII lllll
wilt 1111 dt IIVul 1111111 111111' I ,1,11 (111
) 11,t 'l lr:t 1111 , H'Ellt d ,,,, nl1,il111-1, 111, 11,1,, ,,
if 1\ vh w I \it 1yll111t• , vi, w ,,. ,. 11 ,u d tu, fl 1w1
111
1
1nhh 1u 11lt1tl ,1 dt ll,11111111 '1 lw , 11 vJ, w I 11 a
/1,li/1,
I oll( 1Wl11gI lt , 11. I mq ii 1l111t ti 1t1 w11u•11t vi ft vlr w ✓ I• w1t Ht' 1H t wmduw
\ 11 w dt l,t•tl l11lt11 ,,, 1llu11 1l1111 l11 n• 11mlly ,l(va·d 111 i• Im ,. talllt,

,,, ,,, ,,1 th t JI 1


(,I I /\ 11 VII W (Ju111/lt111111 I
't1 II
If(; ., I r ( I • I r,C>M lt111ttl
WI tr l(f I 11It o 1~ ,
' l
(ntir,lh

£th wrrd1w,, ,
I

IJ1Jflt1llk1n
ul 111 vlow
(i)oudllorn• (/, Vlr un lt«;m• tnt,lu)

ltumNo
11
MIIV. Oro ,j 14 lJO
14
lw Cruom 10 ()()
1/
NorrrkMr, 1t, 00

I luurc 1 I ,'I I ll(l U,rlC µl ,,, VI II ,

A vkw c II be u cd 1111t likt 111y otl1e1 lolile, ft rn11 bl' ,1uerll'd, upd,,t :I, in rt d into, d l ned
from, and joiiwd with otl,cr t,,1,lt• m,t.1 viuw ,
View grcotly extend the wntrol you hove ,>vet your d,1ta, I hey ,re n x II nt way to give
people ou;c ~ to om<' Out ""' 111 or lhu "'''"'" ,lion 111 ., I hie I vcn l<cntl 011/y vi ;w can al.., be
created which mt!nn.s that they, an be ,111t:rwd, but U,cy cannot be ut* tcd to update u_,mmand8,
(Thoush there I a lot thot ,on be d, cu ud ohnul vi ws yet we ore nut going further In
explalnlng vlcwtl a it i beyond the l;opc of thl chapter ,mcl the book,)

11 4 2 Structure of Rclutionol Uotobu ,c;


Con,ider th4' Item, tnblt! of our tfOmplc dntabn l', ft ha thrcf• attribute : JtemNo, Jtem_Namc,
and Prlct, Por each attribuW, there I o M!t of pcrmtth d v Jut , calltd the dL1mazn 11( that attribute.
n ~ e tat-:~ mmbuu.tion of more than one attribute
pro\"ines a 1,..n:.que ,cllue fur e-a.ch row h1 ~~ h'i.b ("~ tlle A Primary i\e\' , c l5
rnore attributes -
group o! ti~ attribu.:es :.s .::.cclaI\:"(,i .i::; :"'rin,ar~· k.c, . ln su~h uniquef\ mer.ti!)
~~ ~p- ~~ke~ -:,x1.sb~ 0fnlo~ thanoni.? ..1ttribute, 1t 1s the refatt\ln.
callee ~~-ite- vriw~-~.
~ primary key :s ~on-redunuant i.e. it d~ not h .1, ~ '-iuplicate vah.:~~ .. 1 th.' '-:,,..e
The m:m-priman -:'\.-c?}" attribute~ 0f a table ('..111 be ref~rred to ;:is ·on-'A--ey attribli,~~
Canon:£me KE)

Occasionall} we may encounlt'r a relation in w·hid, the.re is


more than o~ attribute po_,~ssing the unique identification
property.
Al) attribute cor.~'\"-5
~,~
In our sample database,. there are h, 0 candid t 1 . N relation that can ;:-; ; t
d S e ~evs 5 upp.1 1 0 ndid3tt ~~-
a f th ~
N . C
,-e\ are a ~
an upp- ame m the Suppliers relation B u· :..J te~ tor
ttrib tes ~;- .
COn1.a.1u uruque ,·alues for each h. I
. o 1 o
s· • ese
• are canaNa ~
a U
_.,,,,
Items, ItemNo and Item N . 1P e. 1nularl) , 1n ,ey position.
- - ante are candidate ke) s. i
In the ca.."<! of ru o or more candidate k . _ ot tit,
primary key for the relation. e} ~, the database analyst deodt?~ '--..ne
Alternate Key

In case of hvo or more C"cllldidat k


th • e ·eys on]v
serves as e pnmarv kev. The rest 0 f th ' .; one of the111
., · e.rn are alt
In Suppliers table, Supp_Name is the enzates only.
Ite1ns table Item_Narne is the alte alternate key and in ·mar) t.:1.W ,
pn •
rnate key. Att-en'late f{e)•
allribalP exists, is called a
lhe table that defines the Prinuay-lrq,
....,_,,,,. refers to, is called Prlmaiy table or
ily
Anleradial integtity is a system of mies that a DBMS uses to
~thatreJafiomhips between It:COI~ in tables are
vali4 and that users don't accidentally delete or mange
~ rules that a la.IS uses to
ref W data.
ensure that aetalu.sllips
Yoa can set refetential integrity when all of the £olk;wing beUa:leen ,au.ts • ~
HlllldillititxwmiS are met : tables are Yilld,, and that users

The.maiming field from the primary table is a ~


dodt * .h+◄ alt delele -
dtalwermmldala..
or has a unique index.
related fields have the same data type.
♦ Bolh tables belong to the same database. H the tables are Jinked tables, they IDDSI: be of
DBMS format, and you must open the dan . . they are stored to set
integrity. Referentiaf · · ·-.11i'WW'111ilt 1iov1d bHes from
-•lllb-t.Hlt UAll.a&MUK:D in other f'ormabL
. integrity is ~ y, nlii:ili:ifrvii iutes'.
a value in the foreign ~~'t exist in the
• T'F1'1~ rnigalcey,
that is
tono

Nl'lllll!lteaie
MyS QL w er t d nd upp orte d by MyS Ql AB, a
{ww w .my sql com ) Thi com p ny I now
mp ny ,
a ub 1d1 ry of Sun MtCrtY;]f te, ch
cop yrig ht tom t of the cod b . On Apn l 20th, 2009 Oracle Corp., whi d d vcloJ
the prop tary O l atab , ann oun d a d 'ti
al to acqu ir Sun Micr0; ,
The chi 1n'\r ent r of MyS QL w Michael Wid
niu (a k,a, Monty,. ~yS QJ ba>n na
1'1o nty' d t r My. Th logo of MyS QL, the dolp hin, i nam
ed O
r-n1 ',
11.6 MYSQL DATABASE SYSTEM
The key ro of a data base man ag m nt y tern
1 info rm.a hon ma O
mcn t. A data ba
the ~ to solv ing the prob lem s of info rma tion man
agem ent. In ge <?Ta)., a M!rv ~
relia1:>iv numa1~e a larg e amo unt of data in
a mul ti-us er envi ronm L>nt 60 that ma y ._ ~
:rren ttv acce ss the sam e data . A data base serv
er mus t also prev ent unau th(., , /.J _
de effi. oent solu tion s for failu re reco very .
MyS QL data base syst em refe rs to the com bina
tion of a MyS QL serv er insta nce and a M
data hits e MyS QL oper ates usin g clien t/ser ver
arch itect ure in whic h the serv er run, on 1
mac hine cont aini ng the data base s and clien ts
conn ect to the .6CTVCT over a networ'.G. 1be ten.
ope ratin g sy tern s is usu ally a Linu x (like
Redhat 9,0 etc,) Qr Wind ows oper ating fi'f
Typ icall y MyS QL is supp orte d on Wind ows XP.,
Wind ows Serv er 2003, Red Hat Fedora Linux,
Deb um Unu x, and othe rs. As with any othe r clien
t/ser ver appl icati on., Z.AySQL is a mul
data base syste m., mea ning seve ral user s can
acce ss the data base simu ltan eous ly.
Her e:
<;}The serv er (My SQL serv er) liste ns for clien t
requ ests com ing in over the netw: }:;
acce sses data base cont ents acco rdin g to thos e
requ ests and prov ides that to the diero
<S) Clie nts are prog ram s that conn
ect to the data base serv er and issue queries
pre- spec ified form at. MyS QL is com patib le · i
with the stan dard s base d SQL (Structure!
Que ry Lan guag e). The clien t prog ram may
cont act the serv er prog rarnm atic. aJly (mean:'
a prog ram call the serv er duri ng exec ution )
or man uall y. For exam ple, when you
issu ing com man ds over a sess ion to a MyS
QL serve r., you are issu ing the requests to
serv er by typi ng com man ds at your com man
d prom pt man uall y. On the othe r hand,
you hav e inpu t som e data (say your cred it card
info rma tion on the Inter net toWa!'
purc hase of som e good s) in a form , and the form
is proc esse d by usin g a server
prog ram. , then the MyS QL serv er is cont acte d prog
ramm atica lly. This is often the cast
cred it card appr oval s, mem ber subs crip tion
s etc.
Som e of the key featu res of MyS QL are:
L Spee d. If the serv er hard ware is opti mal,
le¢
MyS QL runs very fast. It supp mts duS
serv ers for dem andi ng appl icati ons.
2.. Ease of USt!!. MyS QL is a high -per form t1:t
ance , relat ively simp le data base syste m. FCOfJl ttJ
beginning, M ySQ L has typic ally been conf igur
ed,
com man d line. How ever , seve ral MyS QL grap hica mon itore d, and managed frOf!'l
l inter face s are also available, ff
3 _ cost . My5 QL is avai lable free of cost. MyS QL is a "Op
en Sour ce" datab ase- M~~
part of LAM P (Lin ux, Apa che, MyS QL, PHP
/ Perl / Pyth on) enviroruJteflt, ,#
owi ng ope n sour ce ente rpris e softw are
. Mor e and mor e com pani es ~ ~
~ as an alter nativ e to expe nsiv e propstack rieta ry softw are stac ks beca use of 1
cost , relia bility ., and docu men tatio n.
· Rl:lATIONAl DATABASES

'- ~ - ~ • S,q,port. MySQL understands standards baled SQL (Structured Query


-'6--&'I.),

5· P~rtahili ty. MySQL provides portabltlity u it haa been tested with a broad range of
di~ferent com p ilers and can work on many different platforms. It is fully multi-threaded
usmg kernel threads. It can easily use multiple CPUs if they are available.
6. Data Type~. M) SQL provides many data types to support different types of data. It also
supports fn,ed-length and \ ariable-length records.
7. Seatrity. MySQL offers a privilege and password system that is very flexible and
secure, and that allows host-based verification. Passwords are secu re because all
password traffic is encrypted when you connect to a server.
8. Scalability and Limits. MySQL can handle large databases. Some real life MySQL databases
contain 50 million records, some have up to 60,000 tables and about 5,000,000,000 rows.
9. Comiecti.vity. Clients can connect to MySQL Server using several protocols:
10. Localizati.on. The server can provide error messages to clients in many languages.
11. Clients and Tools. MySQL provides several client and utility programs. These include
both command-line programs such as mysqldump and mysqladmin, and graphical
programs such as MySQL Administrator and MySQL Query Browser. MySQL Server
has built-in support for SQL statements to check, optimize, and repair tables.

11 7 STARTING MYSQL
Starting MySQL is similar to the way you start other applications in Windows platform. Make
sure that MySQL Server is installed on your machines. Once it is installed, you need to click at
Start ➔ All Programs ➔ MySQL ➔ MySQL Server ➔ MySQL Command Line Client (see

figure below)
~
l!!J ,. ----------~
osoft Word lcJt
'C!I
NetBeans

Ghost(JUm

IC!!I Ghostscnpt

It will start the MySQL client where you have to specify the password. Ask your teacher about
the password for the MySQL installation in your _la__h_. _ _ _ _ _ _ _ __


!Ent password: -
\Je ~ : - to the PtySQL ,.on itoP. CoNIM.tllds end with ; or ,g.
~ Pt SQL connection id is 1
f:~epyuersion: 5.1.33-co-•mity PtySQL Co,..,unity SePuep <CPL)
rype 'help;' OP ·,h' fop help. Type •,c• to cle .... tho buffer.

py::ql> -
"II y o u c rt
a n s t a working in My ,e n You a1e u o u g h w
fr o m M y S Q · . it h you
L b y ly p m g u it at the 1nysq l> p r o m p t (sec f 1 g b e r¼o
Q lo w ) .
t~ , ~
1
L l'()n l'\l!lan • e "~ tl l ; 01
on tt \ to l' , o n • ,u •
u , i fit• lo
1 .3 3 co n 2
nn
14 SQ1, C on
'lt 9 y A un
it ll G et v o
r <GPI,')
p a 'h 'l \l •' ..
0 • ,, 11 ' (0 1·
t , ,c • to c lo t\ l' th n h u ff
\c l\ l- IJP o l" .
ql'> q u
it;~

1 1 .8 t\llYSQL A N
D SQL
I n o r d e r to
access d a ta
Q u e r y Lang w it h in th e M
uage (SQL) . y S Q L d a ta b
SQL is th e s a s e , a ll p r o
U s a g e of SQ e t of c o m m grams and
L has becom a n d s th a t is u s e r s must U
e a s ta n d a r d r e c o g n is e d St;
M y S Q L to b y nearly all
o ls o ft e n a for m o s t o f
a p p li c a ti o n ll o w u s e r s RDB~s. T
s in tu m m u to access d ho ~ g h appli
s t u s e SQL a ta b a s e w it cation p: "
T h e S tr u c tu when execu h o u t d ir e c tl y
r ed Q u e r y L ti n g th e u s u sing SQl,
Telational d a n g u a g e (SQ er 's r e q u e s
a ta b ases, w L ) is a la n g u a g t.
h ic h a re s e ts e th a t e n a b
T h e d a ta b a of r e la te d in le s y o u to c
s e w o r ld is f o r m a ti o n reate and.,
s ta n d a r d la b e c o m in g in s to r e d i n ta
n g u a ge th a c re a s in g ly b le s .
e n v ir o n m e n t can be u in te g r a te d,
t. T he S Q L (S s e d to o p e a n d th is le d
a ll o w s u s e r tr u c tu re d Q u r a te i n m to a c1
s to le a r n o n ery Langua a n y d if f e r e n t k
m a ti o n r e g a e s e t of c o m ge) has pro inds of
r d le s s of w h mands and v e d to b e a
e th e r th e y a u s e it to c r e standard l ~
There are n re w o r k in g a te, r e tr ie v
u m e r o us v e o n a P C, a w e , alter, and ua
Research Lab rs io n s of SQ o r k s ta ti o n , r,,
oratory (n o w L. T h e o r ig a mini, or am
w a s im p l~ m th e Almande in a l v e r s io i:
e n ted a s p a n Research C n ,v a s d e v e
:t of th e S y enter). T h is lo p e d at IBM 3
e v o l: 'e d s m s te m R p r o la ng u a g e , o
c e th e n, ~ d je c t i n e ar ri ginally call~
Institute (AN it
• . SI) p ub lish s n a m e h a s c h a n g e d ly l 9 7 0 s . T
h
e d a n SQL to e Se,1 uel \~~,
u p d a ti o n s m 1
e u d e u p d a ti s ta n d d th SQL. I n 1 9 86, th.e A
o n s in y e a r s a r mc,ica i °N" ,111
S Q L h a s c le at was upd . l.
w e p r e s en t a rl y establi sh e d its e 1992, 200 a te d a g a in m v times f',
a b rie fe d su lf s th t 3 a n d 200 an)
r v e y o{ S QaL 8 d 8.
1 1 .8 .1 P r o . e an a .
c e s s in g C o r d r e la ti o n a ~ bl~
p a b i\ it ie s o l d a tab a s e
t SQL la n g u at> ·
T h e SQL h a
s p r o v e d to
programme b
r s . It offers e a la n a
b y th e f o r a v a ri e ty~ f
m e r a n d th g e tha t _can
c a p a b il it ie s e m o r e co be used by s ,,-e\\ ;,
of SQL a re p ~ o c e s s m g c a p a b il it b o th c a su a
: 111
ie l u s e rs .; .d l t1
P ex b y th e s , s im p ler o 1f~
1 . D a ta
D e fi n it io n
Langua
la tt e r c la s s o f u s e rs .
n e s o f "'
Th e varl
\tis rt""\:
r e la ti o n sch 'D
emas, d e le ti ge , D L ) T
ng . h
re1ations,· c r e S Q L D D L p r
e a ti n in o ,i d e s coll1 rnll1'l:\~' t\'£-;v:
" · ': '
~- Embedde M#nWI
..."''"••
within gl'l1l'l'lll-purpose - -
nnd C', ( t ➔ l'll',
4. View Defiuition. 1hl' SOL DI )L 11l1m Includes cOffllNtA4'
5. A11t1,orl: 11tlo11 1 lw SOI. DDI. include~ commnnds for spedlyltls ...,. ..... to
relations ,1nd Vtl'WS.
6, Integrity. Tlw SQI. provides (limited) form s of lnlcgrHy checking. Future products and
stnndnrd s of SQI. are likely lo include enhanced features for integrity checvmg.
7. Transact/011 Co11trol. SQL inclt1dcs commands for specifying the beginning and ending
of lransacttons nlong with commands to have a control over transaction processin g.

11.8.2 Data Definition Language


DAT_A "iD.l_~TI ONA RY
A database scheme is specified by a sel of definitions which are
expressed by a special language cal1ed a data definition language A Data Dictionary Is a file that
(DDL). The result of compilation of DDL statements is a set of contains "metadata" I. e., "data
about data" .
tables which are stored in a special file ca11ed data dictionary
(or directory).
Whenever data is read or modified in the database system, the data directory is consulted.
The DDL provides a set of definitions to specify the storage structure and access methods used
by the database system.
An ideal DDL should perform the following functions :
1. It should identify the types of data division such as data item, segment, record, and
datn-base file.
2. It should give a unique name to each data-item-type, record-type, file-type, database, and
other data subdivision.
3. It should specify the proper data types.
4. It should specify how the record types are related to make structures.
5. It may define the type of encoding the progrnm uses in the data items (bhrnry, character,
bit, string, etc.). This should not be confoscd with the encoding employed in physical
representation.
6. It may define the length of the data items.
7. It may define the range of values that El cfotn-itcm crin assume.
8. It may specify means of checking for errors in tlw dat,1.
9. It may specify privacy locks for preventing unnulhori~cd t'l~nding or modification of the
data.
10. A logical data d~finilion should not Apecify addressing, ~ndexing, or searchi~g
techniques or specify the placement of data on the storage units, because these topics
are in the domain of physical, not logical, organization.

The SQL commands covered later in this unit, include DDL commands also.
1l '"' " t If, If 1t, II l111 IHU 'Hn lt
I I iii ,11 tt ,1 lo lhl• 1/nioh h1•t111, Ii
1..11 1 dmll fl 1u1,111111 1,ci 111 •· '< 'o, ·1lf1t•, ,,II111 ), I~
1
11 )l\ I 11\ t 6 [I IL cl l111 dlllu, (lfll !% /JIJ/11,H 'JY C '[I~
I I 'o/1/
\J l I "'' ldt U\ \11\ lI '< I~

1
m I dh hlnl h1to 11 , (I II ll ) ( 11 , 11 111a111111
I I li 11 l\llmllh•ll l (IJMI ,) l u111111011d
1 1 11 11
1tl 11 t, Mnntpnlll1 m " 1 ::~'\ ( (;I,)
1
c
01 11111 111d
I I i•n t '1111 II •I ' nnn 11 / oI •m C:0111, of ~
I I( ,11111rn11dM ,,~
tHlff Ion t;Ol11,ol con, ,nond d , " ;.
( ) I II ' I lw lllll 111 H 1'11111
l "''''
I k 011
-..: ut '-'l th rn "'' 1 I llu• ump(• ol lhl 1 ,oo ,
't 6111 ,1'"
l\' ""' l\d thd, un lo 'L') o11l

l ,iA DL t 111111ands ,, ,,
(IX)! ) 1,11111111 r111 de, ris Ih,' 11,,11w But,1,cs1s, ,,flowYou~
l .ksl rdt l~dmllion
tt,1 I ,ngttWt'
to t!ot' dl•lh1 I tll\, ['.) lh~tW <0111111i1nd s, you c,n p~rfor011
Hf' 11 11fl ls' 1'1,·out1h
I ~ 11 •,,11111 ub'(ltfs,
(1)t) ·rti~n Ift,1,mttf tltl/J.c J I
1lilH Rflc•llon I
, ot Dl)J, comm<111dsC 1s cd
m u( 1
·"' fmt' oi \.: rnnHe, u,· \Jc
1 ,J ,, 1 , 11 "'o...J
l, \ ,lijl'dS such c,s n /11/J 1•, n Iv1,•10, on 111, ICl etc. REAfErr.,..

used 10 cac 111, ~, hcm,1 ubj,•>'lN, AL l'hl~ ro11111u11ic s ni-u 11sc, lo inod1fy or
r 11111101, of nh-c,1d1 1•xlRtl11g Ndwm,, nhj1•r1s ond IJl~OJ' rnnrnwnds are us~d to
1 11 1
0 -c •dicmn ohf1•ll~. Ho11w 1'\,t111plu~ 111' s111•h I li11 sin lco1e111 s are : CllEAT!·
ALTllR T \Ill I DRIW 'l'Alll F, ('!{HATH INDF\, ALTFI~ INDEX, DROP INDEX ,r
TABLE, lRllN\.' \l'h lllc,

(11) Gra 111 and 1cvo k,, pl'Ivllrgce nnd 1·0 lrN, 'l'h Is sc1'1i o11 o( I) I) L Co 11 un,mdi is Ul!I
or re, okc pc, 111 is<iuns ,,,. prM I,•gt'N Iu work ti po 11 sl'I 1c, 1111 ob j1•els, For cxnmpl~ aII!
C.IOlt) 11 ho o-en l~s n lnb f,, (s,t)' I11/J/1• I) b,•1·, 11ncs tlw ow 11,•r of ti w I, 1bI,'. The owner of I~
nllo1, ollwrs lo 11•ork on hls/lwr l,1bl,,, ThiN run be ,1chi,•wd by CIUNTing privilege for
~
to othe1 s, 1o l'!'1•okc nh ,,a dy r,tnli•d prlvll,•gcs, I{ EV o KE comm,md is used. fhi, ~
OOL commnnds is also k11uwn ,ts D11111 l'o11lm/ Lmtg11ng,• (DCL) Commands.
(111) ~talntenanct c_o1nn1ands, Thts s,•rtlon of DDI, c,mtm,inds is u<!•d i,'
lnfo1m :ion on ni_nble ''.'1lh n,'. ,lin1 of ntnint,1i11l11g ii. F,,unpl1•s ol t,1h[,, m,1i11t,•u,111cen~
ANAL\ZE IAllLI•, Cl lt·CK 'I'Alll.E. RFl'AIR T.\Jll E. Rl \STORF TAl!LE !'I<',
11 .8.3B DML Commands
B) d l mnnipulntfon, ,, c nwnn :
◊ Utu 1 /11 1 1/ of lnfo1111611011 ll'e .
61
~ tI,c m r, flou of new info, mnt.l l1. tn t11c dntnb,lsl' · ~
A Data ManlpU ~,
~ th\! dcfotio,r of infor1nntion t ton into th"c (inttl b\\SQ, (DML) Is u 1ansu11i! ,r,
user, to ucc:a". ~r~ ~
~ tht' mo t,r,r ,trou of dnta st rom the dnt ll l),lSl\
J • • or&'"' ,J
datn as i ta ni,\'I<'
111 the dnt b
1 ht" DML~ nre bnsknllv ot 1.( .. or~'-l
t ' '' lls~ . nppropriatc ta
., '", H,es :
(r) Prt. et'dw 11 DML.s i~quire ~·!

(i1) Non Prm'td11m/ DMts reg ll,User to spe.:1'f1• 11>/tat data is llt'()clc-.1 and '111 'I' ~l~• '
hm, lo j\l't It. Utre a llSl!r to SPf.'Clf) l<'lm/ d ti~ i• nr~d,•,f "llh•'''1
in a ,
statementD

1l .8.3C TCL Commands


As already mentioned a tra11sactio11 is one complete U
student is a transaction, but it im·olves many steps like - open slu
open marks' table, read data from ,t, calculate pcrcc11tagc a11d grade, write the computti
file and finally close t1icse three tables (student table, marks table and result table).
A transaction is suc<:essfully completed (known as COMMIT) if and only if all its constituent steps
are successfully completed. To manage and control the transactions, the transaction control
commands are used. TI1ese commands manage changes made by DML commands.
Some e,amples of TCL commands are :
COMMIT it makes all the changes made by statements issued, permanent
ROLLBACK it undoes all changes since the beginning of a transaction or since a savepoint
SAVEPOll\T'f it marks a point upto which all earlier statements have been successfully
completed and if required - in case of failure - one may undo the changes
i.e., rollback up to this very point
SET TRANSACTIO!\; it establishes properties for the current transactions.

LET Us REVISE

~ A collection of data is referred to as database and a database


(management) system is basically a computer based record keeping
system.
1. Define the following terms :
~ Database systems help reduce data redundancy, data inconsistency
(a) relation (b) tuple
and facilitate sharing of data, standardization of data and data
(c) attribute (d) domain
security.
(e) primary key (f) candidate key
~ A relational data model organizes the data into tables known as
(g) cartsian product (h) degree relations.
2. What are views ? How are they useful ? ~ A view is a virtual table derived from one or more underlying base
3. Define the following : tables.
(11 primary key (ii) candidate key ~ There is no stored file created for storing a view's contents, rather,
(iii) alternate key (iv) foreign key. only the view definition is stored.
4. What is an Alternate Key ? ~ MySQL is a free, open-source Relational Database Management
S. What is the importance of a Primary System.
Key in a table ? Explain with a suitable ~ A MySQL database system consists of a MySQL server instance and
example. a MySQL database.
6. What do you understand by the terms ~ Some key features of MySQL are : portability, secure system,
Primary Key and Degree of a relation in scalable and supports localization.
relational database ?
~ SQL statements can be classified into : Data Definition Language
7. What do you understand by the terms (DDL), Dara Manipulation Language (DML), Transaction Control
Candidate ley and Cardinality of a Language (TCL), Session Control Language and System Control
relation in relational database ? Language.
............ ,,, .......,
•••..,• r , : . . ◄•Z rw•••olf e
. .. . , . 1 •e• u Sia
atn ... ..t.

Qttjecti,, Type Questions


OTQs
..... .."....e C ce Q es ons
A relational database consists of a collection of
(a) Tables {b) Fields (c) Records (d) Keys
:.. A relational d a ~ con.gsts of a collection of
(a) Tuples (b) Attributes (c) Relations (d) Keys
A(n) _ _ _ in a table represents a logical relationship among a set of values.
(a) Attribute (b) Key (c) Tuple (d) Entry
4.. The term _ _ _ is used to refer to a record in a table.
~) Attribute (b) Tuple (c) Field (d) Instance
5 1h? em ___ is used to refer to a field in a table.
(•) Attribute (b) Tuple (c) Row (d) Instance
6-. A _ _ is a property of the entire relation, which ensures through its value that each tuple
unique in a relation.
(a) Rows (b) Key (c) Attribute (d) Fields
7 Which of. the following attributes cannot be considered as a choice for primary key ?
(•) Id (b) license number (c) Dept_id (d) Street
An attribute in a relation is a foreign key if it is the _ _ _ key in any other relation.
~) Candidate (b) Primaiy (c) Super (d) Sub
9 Consider the table with structure ~ :
Student(ID, naae, dept naae, tot_cred)
In the above table. which attribute will form the primary key ?
(a) Name (b) Dept (c) Total_credits (d) ID
1 Which of the following is not a legal sub-language of SQL ?
(a) DDL (I,) QAL (c) DML (d) TCL

f
.~ illel:tion cl •ignny related data tables is called a _ _
CNpti --. .. of data is known as data _ _
of ml '" whelmrm • field can draw values, is called
--
• I I !'Ian. is celled •
--
• ntl :!Dn-..a:P i m
,. 7
--
aan)Uk-► iltcdedits
--
......... in .. I )1 liol, • a:Bie 4 tis
--
...--. .... ____
__. Nllttan ta .utd - -
tdad Nlltlonl ancl Unktd throql\
laa\Odll

~ :\. p::rr:r~ .i,...~ (""'..., ~.., ~ ~---mph· , ,lhl\.':- in 1t.


L\C"~ ~ttn~~ \)! t'W\.) tat- ~ $ '-•' t,.>,d ,, h.m.''8•' '1-.l'\
- A c..:-~"'Cl ~tti-"'ht~ l'\.f twt) tat- ~ $ c.illoo a furt.'\'1;,0 l-.t', ,r it i:- thl' prim,,11• in ()Ill' tilhll'.
-.m:..::. s.:::.. 'l\iudt ~res a.."1d. d~es ta.Nt>$ and oth~1 d,ltJb,,s..:- ◊hJl'CIB, ts c1.11ll'd DDT..
- "".:..--: c. 5(::... "hkh waruplliates dab in tables is call~ TCL
~~ ('~ s;:::.. ~+.idl ~~ md nunipufa.~ data in tables is call~d DML.
P..... 11 no:~ .\-"re& C"Ont;:cls t:ran....:a.ctions. is called TCL
~~=- ~ ~ iUIU~ c,.f a Cb-ro.mL~ query Ian.oauage us~ by Oracle.

L ,-..::; ~ - d~~ S:J5rml ? l'\'Jwt is its mm ?


.::in:.lt..:on. _~.... da.:abase is a rollection of interrelated data and a database system is basically a computer
ba52G. ~ s5 stenL
_!_ plral file processing 53"5reID suffers from some major limitations like data redimdmm; (duplication
L~

of ciaia)., d;..iil ina:ms:s;ency. :mslU1Table data, unstandardized data, insecu1'e data, incotl'ect data etc. On the
oi..'1er hand, a database system overromes all these limitations and ensures continuous efficiency.
1he arl.vaTUages provided by a database system are :
(1) Reciuc:ed data redundancy (it) Controlled data inconsisten cy
(iii) Shared data (iv) Standardize d data
(u) Secured data (vt) Integrated data.
'Iberefore, to have the systems with increased performanc e and efficiency, the database systems are
p1efe11ed.
2. Can you think of disadvantages of using a datnbase system ? What are these ?
Solution. With the complex tasks to be performed by database systems, certain things may crop up
that may be termed as disadvantag es of using database system. These are :
1. Security may be compromis ed without good controls.
2. Integrity may be compromis ed without good controls.
3. Extra hardware may be required.
4. Performanc e overhead may be significant.
5. System is likely to be complex.
f- /

f.
~ &:aliag
~ tg
0
uag
,__. Rig
0, I g

Do;
♦t I
mltlt\Clt
for dlent llq\lllt l
according to thoae requeata and provld
7. 'vVlznt do yo11 1111dc,~tnnd by My Q
C.olutton . MySQL Clienh are program th.a cormecl M,sQL Wffflf and,. ._ •F •lel • •
pre-specified format Mv5QL is compatible wtth ttaalld.alllt '--1 9QL (91aa I ft ()Illy
Language). The client program may contact the server programmatkally «
manua lJ
8. MySQL provides some com111n11d line programs nnd GUI programs. Name somt oft~
Solutia11 Comma nd line program ms: mysqldump and mysqladmm
Gul program s : MySQL Administrator and MySQL QueryBrowser
9. Whnt is SQL ? What are different categories of commands available in SQL ?
<;elution In order to access data within the Oracle database, all program
s and users must use,
Structured Query Langua ge (SQL). SQL is the set of comma nds that is recogni
sed by nearly all
RDBMSs.
SQL comma nds can be divided into following categories :
1. Data Definit ion Langua ge (DDL) Comma nds.
2. Data Manipu lation Langua ge (DML) Comma nds.
3. Transac tion Control Langua ge (TCL) Comma nds.
4. Session Contro l Comma nds.
5. System Contro l Comma nds.
10. Write the full form of the following abbreviations : (i) DDL (ii) DML CBSE _ '.!oc;
Solution. (i) DDL : Data Definit ion Langua ge
(it) DML : Data Manipu lation Langua ge
11. Differentiate between DDL and DML commands.
Solution The Data Definit ion Langua ge (DDL) comma nds, as the name
suggest s, allow you to
perform tasks related to data definition. That is, through these comma nds,
you can perform tasks
like, create, alter and drop schema objects, grant and revoke privileges etc.
The Data Manipu lation Langua ge (DML) comma nds, as the name suggest s,
are used to manipu late
data. That is, DML comma nds query and manipu late data in existing schema
ob1ects.

GL O SSA R Y
-=:I

Alternate Key A candidate key which is not pnmary key.


Attribute A column of a relation.
Base Table A table having an independent existence ; represented in storage by
a distind stored f e.
Candidate Keys Attribute combinations in a relation that can serve as a primary key.
Cardinality Number of tuples in a relation.
Data Redundancy Duplication of data.
Database Collection of interrelated data.
Database System A combination of a computer based recordkeeping system and a database
.
Degree Number of attributes in a relation.

You might also like