0% found this document useful (0 votes)
0 views

Dbms Lab Manual

The document outlines experiments related to database design, focusing on the E-R model, relational models, and normalization techniques. It covers the identification of relationships, cardinalities, strong and weak entities, as well as key constraints and normalization forms (1NF, 2NF, 3NF, BCNF). The aim is to minimize data redundancy and ensure logical data storage through structured database design.
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)
0 views

Dbms Lab Manual

The document outlines experiments related to database design, focusing on the E-R model, relational models, and normalization techniques. It covers the identification of relationships, cardinalities, strong and weak entities, as well as key constraints and normalization forms (1NF, 2NF, 3NF, BCNF). The aim is to minimize data redundancy and ensure logical data storage through structured database design.
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/ 45

Relevance to PO and PSO’s

EXPERIMENT: 1

Conceptual Design with E–R Model

Aim:
To analyze and identify Relationships, Cardinalities, Strong and Weak entities of Roadway
Travels.
Procedure for Doing the
Experiment:Relationships:
Relationship is an association, dependency or unit between two or more entities and is
represented by a diamond symbol.

All relations have three components.


1. Name:It is the title or entity identifier.

Example:
TICKET

2. Degree:It represents the number of attributes (field) associated with the table or
relation.

Example:

Source
Journey Age
Ticket

TICKET

Departures
Sex Destination
3. Cardinality: It can be the maximum number of records , in one entity that are
linked to a single zero in another entity and vice-versa. Tuples are the number of records in
a relation.

E-R Diagrams for a databases how in relationship of RESERVATION

DepaturesTim
Journey Date

Ticket-No Destination

Sex
Age
Source

TICKET

age sex
Destination name
Source addressc
Passportid
bus availability ontact

RESERVATION PASSENGER
BUS

Passport_id status
Journey_date No.ofseats busnumber
E-R Diagrams for a databases how in relationship CANCELLATION.

TicketNo Destination
Journeydate Source
Sex
Age

DepatureTime
TICKET

age sex

destination name
source address
Passport no
availability contact
BUSNO

CANCELLATIO
BUS N PASSENGER

status

Passport_id

Journey_date No.of seats bus number


Weak Entities:
An entity set that does not possess sufficient attributes to form a primary key is called a weak
entity set.
Strong Entity Set:
One that does havea primary key is called a strong entity set.
Symbolic Representation:

Student_Regno

Strong Entitysets for Roadway Travels

1. passenger 2.Ticket 3.Bus

Ticket_No Bus_No
Passport_No

PASSENGER TICKET BUS

RESULT:

Thus the Relationships, Cardinalities , Strong and Weak entities analyzed and identified
successfully.
EXPERIMENT: 2

Relational Model

Aim:
To represent all the entities(strong, weak) in tabular fashion and represent relationships in a
tabular fashion.
Procedure:
KEY CONSTRAINTS
The following are the different kinds of constraints
1. Domain Integrity constraints
2. Entity Integrity constraints
3. Referential Integrity constraints
A. PRIMARY KEY&NOT NULL

Example:
CREATE TABLE sailors(sid integer,sname varchar(32),rating integerNOTNULL,age
real,PRIMARYKEY(sid));

Table created.

OUTPUT:-

Imposing Integrity Constraint using ALTER


Example: Alter Table Sailors MODIFY sname varchar(32)NOTNULL;

OUTPUT:-

B. DEFAULT
CREATE TABLE sailors (sid integer, sname varchar (32), rating integerNOTNULL,
age real DEFAULT25, PRIMARYKEY (sid));
Example:Practice with your own

Query: TEST OUTPUT


C. UNIQUE
CREATE TABLE sailors(sid integer ,sname varchar(32),UNIQUE,rating integer,age
real DEFAULT25,PRIMARYKEY(sid));

D. FOREIGN KEY
CREATE TABLE reserves ( sid integer not null, bid integer not null, day date time
not null, PRIMARY KEY (sid, bid, day), FOREIGN KEY (sid) REFERENCE
Ssailors(sid));

Adding Foreign Key to an existing Table

Alter table reserves ADD Foreign Key(sid REFERENCES Sailors(sid));Example:

Practice with your own Query:


EXPERIMENT: 3
NORMALIZATION

AIM: Apply the database Normalization techniques for designing relational database
tables to minimize duplication of information like 1NF, 2NF, 3NF,BCNF.

Procedure:
What is Normalizationin DBMS(SQL)?1NF, 2NF,3NF, BCNF Database with Example

What is Normalization?

Normalizationisadatabasedesigntechniquethatreducesdataredundancyandeliminates undesirable
characteristics like Insertion, Update and DeletionAnomalies. Normalization rules divides
larger tables into smaller tables and links them using relationships. The purpose of
Normalization in SQL is to eliminate redundant (repetitive)data and ensure data is stored
logically.

The inventor of the relational model Edgar Codd proposed the theory of normalization of
data with the introduction of the First Normal Form, and he continued to extend theory with
Second and Third Normal Form. Later he joined Raymond F.Boyce to develop the theory of
Boyce-Codd Normal Form.

Database NormalForms

Here is a list of Normal Forms in SQL:

• 1NF(First Normal Form)


• 2NF(Second Normal Form)
• 3NF(Third Normal Form)
• BCNF(Boyce-Codd Normal Form)
• 4NF(Fourth Normal Form)
• 5NF(Fifth Normal Form)
• 6NF(Sixth Normal Form)

The Theory of Data Normalization in MySQL server is still being developed further. For
example,there are discussions even on 6th Normal Form.However,in most practical
applications, normalization achieves its best in 3rd Normal Form.The evolution of
Normalization in SQL theories is illustrated below-
Database Normalization With Examples

Database Normalization Example can be easily understood with the help of a case
study.Assume,a video library maintains a database of movies rented out.Without any
normalization in database,allin formation is stored in one table as shown below. Let's
understand Normalization database with normalization example with solution:

HereyouseeMovies Rentedcolumnhasmultiplevalues.Nowlet'smoveinto1stNormalForms:

1NF(FirstNormalForm)Rules

• Eachtablecellshouldcontainasinglevalue.
• Eachrecordneedstobeunique.

The above table in

1NF-1NFExample
Example of1NFinDBMS

Beforeweproceedlet'sunderstandafewthings--
WhatisaKEYinSQL?

A KEY in SQL is a value used to identify records in a table uniquely. An SQLKEY is a


single column or combination of multiple columns used to uniquelyidentify rows or tuples
in the table. SQL Key is used to identify
duplicateinformation,anditalsohelpsestablisharelationshipbetweenmultipletablesinthedataba
se.

Note:ColumnsinatablethatareNOTusedtoidentifyarecorduniquelyarecallednon-keycolumns.

WhatisaPrimaryKey?

PrimaryKeyinDBMS

Aprimaryisasinglecolumnvalueusedtoidentifyadatabaserecorduniquely.It
hasfollowingattributes.
• AprimarykeycannotbeNULL
• Aprimarykeyvaluemustbeunique
• Theprimarykeyvaluesshouldrarelybechanged
• Theprimarykeymustbegivenavaluewhenanewrecordisinserted.
WhatisCompositeKey?

Acompositekeyisaprimarykeycomposedofmultiplecolumnsusedtoidentifyarecorduniquely.
Inourdatabase, we havetwopeoplewiththesamenameRobertPhil,buttheyliveindifferentplaces.

CompositekeyinDatabase

Hence,werequirebothFullNameandAddresstoidentifyarecorduniquely.Thatisacompositekey.
Let'smoveintosecondnormalform2NF

2NF(SecondNormalForm)Rules

• Rule1-Bein1NF
• Rule2-
SingleColumnPrimaryKeythatdoesnotfunctionallydependantonanysubsetofcandidatekeyrelation

Itisclearthatwecan'tmoveforwardtomakeoursimpledatabasein2ndNormalizationformunlessw
epartitionthetableabove.

Wehavedividedour1NFtableintotwotables
viz.Table1andTable2.Table1containsmemberinformation.Table2containsinformationonmovie
srented.
We have introduced a new column called Membership_id which is the
primarykeyfortable1.RecordscanbeuniquelyidentifiedinTable1usingmembershipid

Database-ForeignKey

InTable2,Membership_IDistheForeignKey

ForeignKeyinDBMS

ForeignKeyreferencestheprimarykeyofanotherTable!IthelpsconnectyourTables

• Aforeignkeycanhave a differentnamefromitsprimarykey
• Itensuresrows inonetablehavecorrespondingrowsinanother
• UnlikethePrimarykey,theydonothavetobeunique.Mostoftentheyaren't
• Foreignkeyscanbenulleventhoughprimarykeyscannot
Whydoyouneedaforeignkey?

Suppose,anoviceinsertsarecordinTableBsuchas

You will only be able toinsertvaluesinto yourforeign key that existin


theuniquekeyintheparenttable.Thishelpsinreferentialintegrity.

TheaboveproblemcanbeovercomebydeclaringmembershipidfromTable2asforeignkeyofmem
bershipidfromTable1

Now,ifsomebodytriesto insertavalueinthe
membershipidfieldthatdoesnotexistintheparenttable,anerrorwillbeshown!
Whataretransitivefunctionaldependencies?

Atransitivefunctionaldependencyiswhenchanginganon-
keycolumn,mightcauseanyoftheothernon-keycolumnstochange

Considerthetable1.Changingthenon-keycolumnFullNamemaychangeSalutation.

Let'smoveinto3NF

3NF(ThirdNormalForm)Rules

• Rule1-Bein2NF
• Rule2-Hasnotransitivefunctionaldependencies

Tomoveour2NFtableinto3NF,weagainneedtoagaindivideourtable.

3NFExample

Belowisa3NFexample inSQLdatabase:
Wehaveagaindividedourtables andcreatedanewtablewhichstoresSalutations.

There are no transitive functional dependencies, and hence our table is in


3NFInTable3SalutationIDis primarykey, andinTable
1SalutationIDisforeigntoprimarykeyinTable3

Nowourlittleexampleisatalevelthatcannotfurtherbedecomposedtoattainhigher normal form


types of normalization in DBMS. In fact, it is already inhigher normalization forms.
Separate efforts for moving into next levels
ofnormalizingdataarenormallyneededincomplexdatabases.However,wewillbediscussingnextlevel
sofnormalisationinDBMSinbriefinthefollowing.

BCNF(Boyce-CoddNormalForm)

Evenwhenadatabaseisin3rdNormalForm,stilltherewouldbeanomaliesresulted
ifithasmorethanoneCandidateKey.

SometimesisBCNFisalsoreferredas3.5NormalForm.

4NF(FourthNormalForm)Rules

Ifnodatabasetable
instancecontainstwoormore,independentandmultivalueddatadescribingtherelevantentity,then
itisin4thNormal Form.

5NF(FifthNormalForm)Rules

Atableisin5thNormalFormonlyifitisin4NFanditcannotbedecomposedintoanynumberofsmalle
r tableswithoutlossofdata.

6NF(SixthNormalForm)Proposed

6thNormalFormisnotstandardized, yethowever,itisbeingdiscussedbydatabase experts for


some time. Hopefully, we would have a clear &standardizeddefinitionfor6thNormal
Forminthenearfuture...
That's alltoSQLNormalization!!!
Exp. N~
. - - - --.-
=Le_ -_
-
Roll No: Date:
- ..
-- - - ------ -- - - -- - - .

·--- . ---·· -·- __,,

.I·- -- - - - - - - - - - - - - - - -- - --

~ ( EfYW tJ O N\)fVl ,~F ~ L, ) 1 f- W\Mt


, \rbQc -+W R[ '2-o), JD B "AQc: ¼AA {\o) , S)E?t - No Nu\"'1~~1? C3);9 M 'L
~ \\J' 0 MB~ { ~,~))j

I· ; I ~~ ~~ iu e~ ok,, a ---ro1.0~ 0-.ff2ec_{ej


~

.·.· ~) s_y J(;.':::l ocn ;;mBI E ~~


--
1- - -- - - -- - - - - - - - - - - -- -
' --

, .. ~~vrt-a:){J- C,<'e_cdo ⇒ab\e 1>£?:T t'!ff?1ND NtJ~ '.R {~"l ~ f(\0-~tey/


:; ,
.
-
'I
-':::::2 D ~ +\M}: ·'\Jffic\-\i-\1-Z ')_ llc:,°"}J Lo L \l l\Rt ttbR?- ( to'>)_:

. ';:' j) ~
1: --=------ <:""""" "-
0-- ~ltu,'\i: J.rLetMe:fub te ~-
-'-::"c::::::::= .
••' I

:, ·• - -- - -- - -----: ---.-- ----- ----------

.i ~Y\~ 'll} +'\ ~ ±~l11. ~M'\? o..:i.a Eer ~f-.,<e.Y\C{_ t}\llYl\.:.Yb)~


I' - - DJ-- ~Jr; e_~0 ak; 01u:02 ()_~c ,W '

ST. MAR TIN'S ENGINEERING COLLEGE Page No.


✓a. \v-1
Ir c\ll""' na ff'\.l ''Jpt
t,JUI. L
fMPNO ~ \)1-n\•r< ( t) -
tJo1 tH)( l
f pn~~,r "°'-" h,-o ho) t-}Ol" tlt)ll -·-
'l)....ft "'C 7 ( 11:1) ~

JOO
l)f PT.No
~\)f<\ bt"!" (3')
)')Jll ~-·
~
sAl Numhe--< (:t1~) tlUL l

✓0-~ \.,\: _
I
-~~l \J\Ylr' r'lllfr\4.. 7"ij?~
.p-i, ("(10..~ \-: !.~ j
DF ?T NO u1'11k...,..l;)
,,1

0 N f\ f',1 f Va1cr,.n1 (I c~) L


N \)~ 7
Loe.
\tr<clwc(w) NuLt... (
~

[fofimn ~w--r=r\\~ ✓3\u..e \


f \\.'\PNO /t,u 1~hyt;J NuL L
.
-
t-NA r-if V).·d,.n; fl ~ NOTN ul L
_,...o
~\I ~
... IVl.'i C}''J'Y;! : t I\\O"T N \JL L
ItJuma'-:i~}, ,,
... ' l- £.\')
C-'i-!-
,I L
NUL
.~ . . l
~~ ~ 1 !N-Jr(l k"l((:=:h NlJl-L -
!.: .. , t'
I.., '
' N\lrf' t!-~~i NDLL l
-

~ll
Exp. No: Roll No:
Date:

- - ----- - - - -
,4~4 Q't to h.1.Ylln v),j-\h ~_ef!lpl_.ioi==:._-_-•·•=---_
Ji- ~~ ~,~ \~~~'c,-t (~~ rnadi ·G1 :J u~~~(i~o-< r., ~~- -
-:-- ~~ D~~,,-- ~~ 01( 1 :m::::tv~~ a. +kc~_J, _ _
~~

' 5) l 71 ~ .~'de_ ernp\ (1:,\~ ero.m.t t e.tn~n~J ad~ (M11mJ~ -du


t,~~ e.m?n~ w¼\'<- e~ bY1:=) , , -e. , ~¥:Pn~-::,, tcro

--
b") ~ £> an~ ct,""'"'"'<c.m \l~=kb.J_ULJ.·k~b'--- - - - - - -
'1'/'\

, ~l}Y\~~ -h\ ~bl~ . F,1-1 P 1));'t) r C0>~llrnr? exp:,

ST. MARTIN'S ENGINEERIN G COLLEGE Page No.


Q.t'<lf ft 0

' la \ll'1 n .D atv\.l._ - ' \\l'c2_ ✓a-..\ \N1


C tA~tH> l'J1.~ u
t..-~tf'-£:
~101'<\ 'be.re L6)

\l"o...-t Ct\o.·•o-l1-0") , N01N0[L' · I


\ -se;s \J ~ <l"\(;,_",{). ( ').~ .NOT NULL'f
-1
\
~?,>N"> N ~m be.Yl.3) -~) n l
._ V -
-L r
~

I
~~ L 7-•~-•'J
·\ N,tr-ti 'ct'< ( :::/-ti..) '/\) l . )
.. v_, _# •
t,
I

'6)~~-
(_ D l uJ"' n Y\QlY1<l.. \ e_ ✓o...t~ -
l
; -Mlj>NO N \u()~ -f( G)
J
~ulL
f -:-....f\\N"l t \} D-'fth,..·-o .h~ NOi ~ \Jl L
j
I .. ,~
!
~
.... ) # 4', \l 0-"t&o.1"'-l'2D) NOT N \.)LL '
l
~ ..._ , -7 -
~' :' . - \J •)' NIJJn"b~ l'0 N\JL-l
i I ,'-''->J'(}\ei-r
j

'.
~f- ;___ i l:\;)) NvLL
Exp. N o: 5' R ol f N o: D at e:

Pa ge No .
0 (_

C'SD

ftv\\)NO €:_l,J-f\Mt 00-s OE- ?'T- t ID SAL'


\o, ~ ·H'R
', ~~gev-
:t t, ~ 5.Q'()t)

\ 1b J_ s ::-J L-1 '"35C;J)O


\ \ t> < )et.\w{eY 7.... f"\ G oocro_l
' '
I l

E- _NAME Jol3
~
- ~-\K
- --
s l"~1'i:f\O.~J(

\_ -r ----·-
J.tt.¼--{Q_~ l

. .. \
'
1
~tf\~Nt) £-N~Mt Jt)~ \'uE?T,No ~~L l

Io~ \. e.~--<3'< I
I ~C.J l.tOCLi.)
I
\ -
t- Exp.No: Roll No: Date:

~ I~ ±~ ~~~ ~f' ,1,,_J~ u-t~~b:.J ioJo~J ~:;~


_ ch~ceJJ~ Cif&21 ~
52:1~~~ teMP (Y(dQ,yhj SAL Dtsc; -
S~cJi>t"Eld)ty) -
- - ~~Gi_UQ.,wok,D~~~a~LW

6) o; ~~ y dork n0 ~*b \-(:_ ~plo 'dee.. a vt<h ct V39 du? \~ cdfd


vo\ua.~

9)u~~ :tho <:J:np ss-ah\~ :±o A& ~ s~ °1J' a_t\ eM~&~@


--\-n Q. s '-S~\- wk-D@. w t-sk,Y'B ~ vto.~l•

-
l0 teW.t_ (l(1\ ~ ~ •:,e \no cm Ul?ffi'f'!'.('i (!;, ~ •
lv

~~ ',---DJ.cv~ hnr0_£~_t? _wb,{(;_-YOO:_' LlfCh"'t-< ; _ __


- 0titpui~ ~ \Jdl'jO~., 1_~w rAffrc~ '!.J . ______
- .
ST MARTIN·s ENGINEERING COLLEGE Page No.
-=14
~o

tMrf\10 f_NAME JOB ocrr-t-Jo ~A'L


\0' X t
- :Y5CS:D
--
S· Mo~" =!--1../ $(5f;t-:)
\ O's T )tc+.,_.<er( ~ () l rt;GTY'::)
-- - ---- . ·-- ...__

vsc::oc
Zo oo
~-\ l '.J F-t~.+;<t \ J~' \tx: Pr-t\a ~-i+L 7
I
-- -
__ t'.iR
\ J
I \<: .2~ r -
'I
......,
· I
~ ~

,... ~t ~
!) ,..,
' lliO t'\.JJ~X \ °=t-\J
t ~ . 'S"Obv- -

You might also like