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

DATABASES AND COMPILER LAB DATABASES Objective: This lab enables the students to practice the concepts learnt

in the subject DBMS by developing a database for an example company named " oad!ay Travels" !hose description is as follo!s" The student is expected to practice the designing# developing and $uerying a database in the context of example database " oad!ay travel"" Students are expected to use "Mys$l" database" Roadway Travels " oad!ay Travels" is in business since %&&' !ith several buses connecting different places in (ndia" (ts main office is located in )yderabad" The company !ants to computeri*e its operations in the follo!ing areas: %" eservations +" Tic,eting -" .ancellations Reservations: eservations are directly handled by boo,ing office" eservations can be made /0 days in advance in cither cash or credit" (n case the tic,et is not available# a !ait listed tic,et is issued to the customer" This tic,et is confirmed against the cancellation" Cancellation and Modifications: .ancellations are also directly handed at the boo,ing office" .ancellation charges !ill be charged" 1ait listed tic,ets that do not get confirmed are fully refunded" ee! l : E"R Model 2naly*e the problem carefully and come up !ith the entities in it" (dentify !hat data has to be persisted in the database" This contains the entities# attributes etc" (dentify the primary ,eys for all the entities" (dentify the other ,eys li,e candidate ,eys# partial ,eys# if any" 3xample: 3ntities: %" B4S +" Tic,et -" 5assenger 5 (M2 6 736 2TT (B4T3S: %" Tic,et (D 8Tic,et 3ntity9 +" 5assport (D 85assenger 3ntity9 2part from the above mentioned entities you can identify more" The above mentioned are fe!" ee! # : Conce$t desi%n wit& E"R Model elate the entities appropriately" 2pply cardinalities for each relationship" (dentify strong entities and !ea, entities 8if any9" (ndicate the type of relationships 8total : partial9" Try to incorporate generali*ation# aggregation# speciali*ation etc !herever re$uired" 3xample: 3; diagram for bus

ee! ' : Relational Model epresent all the entities<8Strong# 1ea,9 in tabular fashion" epresent relationships in a tabular fashion" Then are different !ays of representing relationships as tables based on the cardinality" epresent attributes a: columns in tables or as tables based on the re$uirement" Different types of attributes 8.omposite# Multivalued and Derived9 have different !ay of representation" 3xample: The passenger tables loo, as belo!" This is an example" 6ou can add more attributes based on your 3; model" =ame 2ge Sex 2ddress 5assport (D

ee! ( : Nor)ali*ation Database normali*ation is a techni$ue for designing relational database tables to minimi*e duplication of information and# in so doing# to safeguard the database against certain types of logical or structural problems# namely data anomalies" >or example# !hen multiple instances of a given piece of information occur in a table# this possibility exists that these instances !ill not be ,ept consistent !hen the data !ithin the table is updated# leading to a loss of data integrity" 2 table that is sufficiently normali*ed is less vulnerable to problems of this ,ind because its structure reflects the basic assumptions for !hen multiple instances of the same information should be represented by a single instance only" ee! + : Installation of Mys,l and $racticin% DDL co))ands (nstallation of MyS$l" (n this !ee, you !ill learn .reating databases# )o! to create tables# altering the database# dropping tables and databases (f not re$uired" 6ou !ill also try truncate# rename commands etc" E-a)$le for creation of a table" . 32T3 T2B?3 5assenger 85assport id (=T3@3 5 (M2 6 736# =ame .)2 8A09 =4??# 2ge (nteger# Sex .har9B =ote: Detailed creation of tables is given at the end" ee! . : Practicin% DML co))ands DM? commands are used for managing data !ithin schema objects" Some examples: S3?3.T ; retrieve data from the a database (=S3 T ; insert data into a table 45D2T3 ; updates fisting data !ithin a table B D3?3T3 ; deletes all records from a table# the space for the records remain Insertin% val/es into B/s ta0le: (nsert into Bus values 8%+-C#<hyderabad<# <tirupathi<9B (nsert into Bus values 8+-CA#<hyderabdD#DBanglore<9B Insertin% val/es into Passen%er ta0le: (nsert into 5assenger values 8%#CA#<ramesh<# CA#<M<#<abcl+-<9B (nsert into 5assenger values 8+#'E#<geetha<# -/#<><#<abcl+C<9B >e! more 3xamples of DM? commands: Select F from BusB 8selects all the attributes and display9 45D2T3 B4S S3T Bus =o G % 1)3 3 B4S =OG+B

ee! 1 : 2/eryin% (n this !ee, you are going to practice $ueries 8along !ith sub $ueries9 using 2=6# 2??# (=# 3xists# =OT 3H(STS# 4=(O=# (=T3 S3.T# .onstraints etc" Practice t&e followin% 2/eries: %" Display uni$ue 5= Ino of all passengers" +" Display all the names of male passengers" -" Display the tic,et numbers and names of all the passengers" C" Display the source and destination having journey time more than %0 hours" A" >ind the tic,et numbers of the passengers !hose name start !ith <2< and ends !ith J)D" /" >ind the names of passengers !hose age is bet!een -0 and CA" '" Display all the passengers names beginning !ith J2< E" Display the sorted list of passengers names &" Display the Bus numbers that travel on Sunday and 1ednesday %0" Display the details of passengers !ho are traveling either in 2.;or =O=I2.84sing only (= operator9 ee! 3 and wee! 4 : 2/eryin% 5contin/ed6667 6ou are going to practice $ueries using 2ggregate functions 8.O4=T# S4M# 2K@# and M2H and M(=9# @ O45 B6# )2K(=@ and .reation and dropping of Kie!s" %" 1rite a Luery to display the (nformation present in the 5assenger and cancellation tables" )int: 4se 4=(O= Operator" +" 1rite a Luery to display different travelling options available in British 2ir!ays" M Display the number of days in a !ee, on !hich the &10% bus is available" -" >ind number of tic,ets boo,ed for each 5= Ino using @ O45 B6 .?24S3" )int: 4se @ O45 B6 on 5= I=o" C" >ind the distinct 5= numbers that are present" A" >ind the number of tic,ets boo,ed in each class !here the number of seats is greater than (" )int: 4se @ O45 B6# 1)3 3 and )2K(=@ .?24S3S" /" >ind the total number of cancelled seats" '" 1rite a Luery id count the number of tic,ets for the buses# !hich travelled after the date < %C:-:+00&<" )int: 4se )2K(=@ .?24S3S" ee! 89 : Tri%%ers (n this !ee, you are going to !or, on Triggers" .reation of insert trigger# delete trigger# update trigger" 5ractice triggers using the above database" E%: . 32T3 T (@@3 updchec, B3>O 3 45D2T3 O= passenger >O 32.) O1 B3@(= (> =31"Tic,ent=O N /0 T)3= S3T =e!"Tic,ent no G Tic,et noB 3?S3 S3T =c!"Tic,ctno G 0B 3=D (>B 3=DB e e ! 88 : Proced/res (n this session you are going to learn .reation of stored procedure# 3xecution of procedure and modification of procedure" 5ractice procedures using the above database" E%: . 32T3 5 O.3D4 3 my5roc89 B3@(= S3?3.T .O4=T8Tic,ets9 > OM Tic,et 1)3 3 ageNGC0B 3ndB

ee! 8# : C/rsors (n this !ee, you need to do the follo!ing: Declare a cursor that defines a result set" Open the cursor to establish the result set" >etch the data into local variables as needed from the cursor# one ro! at a time" .lose the cursor !hen done # E%: . 32T3 5 O.3D4 3 my5roc8inIcustomerOd (=T9 B B3@(= D3.?2 3 vIid (=TB D3.?2 3 vIname K2 .)2 8-09B D3.?2 3 cl .4 SO >O S3?3.T std(d#-td>irstname > OM students 1)3 3 std(dGinIcustomerIidB O53= clB >3T.) cl into vIid# vInameB .lose clB < 3=DB Ta0les: B:S: Bus =o: Karchar: 57 Source : Karchar Destination: Karchar Passen%er: 5= I=o : =umeric8&9 : 57 Tic,etI=o: =umeric 8&9 =ame: Karchar8%A9 2ge: int 8C9 Sex:.har8"%09: Male:>emale 55=O: Karchar8 %A9 Reservation: 5= I=o: =umeric8&9: >7 OourneyIdate: datetime8E9 : =oIofIseats: int 8E9 2ddress : Karchar 8A09 .ontactI=o: =umeric 8&9 PN Should not be less than & and Should not accept any other character other than (nteger Status: .har 8+9: 6es : =o Cancellation: 5= I=o: =umeric8&9: >7 OourneyIdate : datetime8E9 "" =oIofIseats: int 8E9 2ddress : Karchar 8A09 .ontactI=o: =umeric 8&9 PN Should not be less than & and Should not accept any other character other than (nteger Status: .har 8+9: 6es : =o Tic!et: Tic,etI=o: =umeric 8&9: 57 Oourney"Idate: datetime8E9 2ge : int 8C9 Sex:.har8%09: Male : >emale Source : Karchar Destination: Karchar DepItime : Karchar