Dbms Lab Manual
Dbms Lab Manual
EXPERIMENT: 1
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.
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.
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
Student_Regno
Ticket_No Bus_No
Passport_No
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:-
OUTPUT:-
B. DEFAULT
CREATE TABLE sailors (sid integer, sname varchar (32), rating integerNOTNULL,
age real DEFAULT25, PRIMARYKEY (sid));
Example:Practice with your own
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));
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
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.
1NF-1NFExample
Example of1NFinDBMS
Beforeweproceedlet'sunderstandafewthings--
WhatisaKEYinSQL?
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
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.
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
.I·- -- - - - - - - - - - - - - - - -- - --
. ';:' j) ~
1: --=------ <:""""" "-
0-- ~ltu,'\i: J.rLetMe:fub te ~-
-'-::"c::::::::= .
••' I
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
~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, _ _
~~
--
b") ~ £> an~ ct,""'"'"'<c.m \l~=kb.J_ULJ.·k~b'--- - - - - - -
'1'/'\
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
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:
-
l0 teW.t_ (l(1\ ~ ~ •:,e \no cm Ul?ffi'f'!'.('i (!;, ~ •
lv
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- -