Sie sind auf Seite 1von 37

DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

INDEX

S.no Name of the experiment Page no

1. E-R Model

2. Conceptual Design with E-R Model

3. Relational Model

4. Normalization

Installation of Mysql and practicing DDL


5. commands

6. Practicing DML commands

7. Querying

8. Querying

9. Querying
10.
Triggers
11.
Procedures
12.
Cursors

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 1


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Database Management Systems Lab


B.Tech 2018-2019 (R16) II year II sem

B.Tech. II Year II Sem. L/T/P/C

Course Code: CS407ES 0/0/3/2

Course Objectives: This lab enables the students to practice the concepts learnt in the subject DBMS by
developing a database for an example company named “Roadway Travels” whose description is as
follows. The student is expected to practice the designing, developing and querying a database in the
context of example database “Roadway travels”. Students are expected to use “Mysql” database.

Course Outcomes:

 Ability to design and implement a database schema for given problem.


 Apply the normalization techniques for development of application software to realistic problems.
 Ability to formulate queries using SQL DML/DDL/DCL commands.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 2


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

ROADWAY TRAVELS

“Roadway Travels” is in business since 1977 with several buses connecting different places in
India. Its main office is located in Hyderabad.

The company wants to computerize its operations in the following areas:

 Reservations

 Ticketing

 Cancellations

Reservations :

Reservations are directly handled by booking office. Reservations can be made 60 days in
advance in either cash or credit. In case the ticket is not available, A wait listed ticket is issued to the
customer. This ticket is confirmed against the cancellation.

Cancellation and modification:


Cancellations are also directly handed at the booking office. Cancellation charges will be
charged. Wait listed tickets that do not get confirmed are fully refunded.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 3


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

EXPERIMENT -1

AIM: Analyze the problem and come with the entities in it. Identify what Data has to be
persisted in the databases.

The Following are the entities:

1 .Bus

2. Reservation

3. Ticket

4. Passenger

5. Cancellation

The attributes in the Entities:

Entity Name: Bus:

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 4


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Entity Name: Reservation:

Entity Name: Ticket

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 5


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Entity Name: Passenger

Entity Name: Cancellation

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 6


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

EXPERIMENT-2

AIM: Concept design with E-R Model

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 7


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

EXPERIMENT-3

AIM: Represent all entities in a tabular fashion. Represent all relationships in a tabular fashion.

The following are tabular representation of the above entities and relationships

Bus:

COLOUMN NAME DATA TYPE CONSTRAINT

Bus No varchar2(10) Primary Key

Source varchar2(10)

Destination varchar2(10)

Couch Type varchar2(10)

Reservation:

COLOUMN NAME DATA TYPE CONSTRAINT


PNRNo
number(9) Primary Key
Journey date Date

No-of-seats integer(8)

Address
varchar2(50)
Contact No
Number(9)
BusNo
varchar2(10) Foreign key
Seat no
Number

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 8


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Ticket:

COLOUMN NAME DATA TYPE CONSTRAINT

Ticket_No number(9) Primary Key

Journey date Date

Age int(4)

Sex Char(10)

Source varchar2(10)

Destination varchar2(10)

Dep-time varchar2(10)

Bus No Number2(10)

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 9


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Passenger:

COLOUMN NAME DATA TYPE CONSTRAINT

PNR No Number(9) Primary Key

Ticket No Number(9) Foreign key

Name varchar2(15)

Age integer(4)

Sex char(10) (Male/Female)

Contact no Number(9) Should be equal to 10 numbers

and not allow other than

numeric

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 10


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Cancellation:

COLOUMN NAME DATA TYPE CONSTRAINT

PNR No Number(9) Foriegn-key

Journey-date Date

Seat no Integer(9)

Contact_No Number(9) Should be equal to 10 numbers

and not allow other than

numeric

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 11


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

EXPERIMENT- 4

AIM: Normalization
Database normalization is a technique for designing relational database tables to minimize
duplication of information and, in so doing, to safeguard the database against certain types of logical or
structural problems, namely data anomalies. For example, when multiple instances of a given piece of
information occur in a table, the possibility exists that these instances will not be kept consistent when
the data within the table is updated, leading to a loss of data integrity. A table that is sufficiently
normalized is less vulnerable to problems of this kind, because its structure reflects the basic
assumptions for when multiple instances of the same information should be represented by a single
instance only.
For the above table in the First normalization we can remove the multiple valued attribute Ticket_id and
place it in another table along with the primary key of passenger.
First Normal Form: The above table can have divided into two tables as shown below.

Passenger
Name Age Sex Address Ticket_id Passport ID

Passport ID Ticket_id

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 12


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

EXPERIMENT- 5

AIM: Installation of Mysql and practicing DDL commands


Step1
Make sure you already downloaded the MySQL essential 5.0.45 win32.msi file. Double click
on the .msi file.

Step2
This is MySQL Server 5.0 setup wizard. The setup wizard will install MySQL Server 5.0
release 5.0.45 on your computer. To continue, click next.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 13


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Step3
Choose the setup type that best suits your needs. For common program features select Typical
and it’s recommended for general use. To continue, click next

Step 4:This wizard is ready to begin installation. Destination folder will be in C:\Program
Files (x86) \MySQL\MySQL Server 5.1\. To continue, click next.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 14


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Step 5
The program features you selected are being installed. Please wait while the setup wizard
installs MySQL 5.0. This may take several minutes.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 15


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Step6
To continue, click next.

Step7
To continue, click next.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 16


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Step8
Wizard Completed. Setup has finished installing MySQL 5.1. Check the configure the MySQL
server now to continue. Click Finish to exit the wizard

Step 9
The configuration wizard will allow you to configure the MySQL Server 5.0 server instance. To
continue, click next.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 17


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Step10
Select a standard configuration and this will use a general-purpose configuration for the
server that can be tuned manually. To continue, click Next.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 18


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Step 11:
Check on the install as windows serviceand include bin directory in windows path. Tocontinue, click
Next.

Step12 Please set the security options by entering the root password and confirm retype the
password.continue, click Next.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 19


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Step13
Ready to execute? Clicks execute to continue.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 20


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Step 14
Configuration file created. Windows service MySQL5 installed. Press finish to close the
wizard.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 21


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

EXPERIMENT-6

AIM: Practicing DDL & DML Commands

Data Definition Language

The data definition language is used to create an object, alter the structure of an object and also drop
already created object. The Data Definition Languages used for table definition can be classified into
following:

1)
Create table command


2)
Alter table command

3)
Truncate table command

4)
Drop table command

1) Creating of Tables on ROAD WAY TRAVELS:

Table is a primary object of database, used to store data in form of rows and columns. It is created
using following command:

Create Table <table_name> (column1 datatype(size), column2 datatype(size),


・_,column(n) datatype(size));

Where, table_name is a name of the table and coulumn1, column2 _ column n is a name of the column
available in table_name table.

R Each column is separated by comma.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 22


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Pointes to be remember while creating a table.



Table Name must be start with an alphabet.


Table name and column name should be of maximum 30 character long.



Column name should not be repeated in same table.


Reserve words of Oracle cannot be used as a table and column name.



Two different tables should not have the same name.


Underscores, numerals and letters are allowed but not blank space or single quotes.

Example:

 SQL> create table Bus(Bus_No varchar(5), source varchar(20), destination varchar(20),CouchType


varchar2(10),fair number);

Table Created.

Desc command

Describe command is external command of Oracle. The describe command is used to view

the structure of a table as follows.

Desc <table name>

 SQL> desc bus;

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 23


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Name Null? Type

----------------------------------------- -------- ----------------------------

BUS_NO NOT NULL INTEGER2(5)

SOURCE VARCHAR2(20)

DESTINATION VARCHAR2(20)

CouchType VARCHAR2(10)

FAIR NUMBER

Reservation Table:

 SQL> create table Reservation(PNR_NO Numeric(9), No_of_seats Number(8), Address


varchar(50), Contact_No Numeric(9), Status char(3));

Table created.

 SQL> desc Reservation

Name Null? Type

----------------------------------------- -------- ----------------------------

PNR_NO NUMBER(9)

NO_OF_SEATS NUMBER(8)

ADDRESS VARCHAR2(50)

CONTACT_NO NUMBER(9)

STATUS CHAR(3)

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 24


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Cancellation Table:

 SQL> create table Cancellation(PNR_NO Numeric(9), No_of_seats Number(8), Address


varchar(50), Contact_No Numeric(9), Status char(3));

Table created.

 SQL> desc Cancellation

Name Null? Type

----------------------------------------- -------- ----------------------------

PNR_NO NUMBER(9)

NO_OF_SEATS NUMBER(8)

ADDRESS VARCHAR2(50)

CONTACT_NO NUMBER(9)

STATUS CHAR(3)

Ticket Table:

 SQL> create table Ticket(Ticket_No Numeric(9) primary key, age number(4), sex char(4) Not null,
source varchar(2), destination varchar(20), dep_time varchar(4));

Table created.

SQL> desc Ticket

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 25


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Name Null? Type

----------------------------------------- -------- ----------------------------

TICKET_NO NOT NULL NUMBER(9)

AGE NUMBER(4)

SEX NOT NULL CHAR(4)

SOURCE VARCHAR2(2)

DESTINATION VARCHAR2(20)

DEP_TIME VARCHAR2(4)

2) Alteration of Table

Once Simple Table is created, if there is a need to change the structure of a table at that time

alter command is used. It is used when a user want to add a new column or change the width

of datatype or datatype itself or to add or drop integrity constraints or column. (we will see

about constraints very soon.).i.e. table can be altered in one of three way : by adding

column, by changing column definition or by dropping column.

Addition of Column(s)

Addition of column in table is done using:

Alter table <table_name> add(column1 datatype, column2 datatype ・_);

Add option is used with alter table_ when you want to add a new column in existing table. If you
want to Add more than one column then just write column name, data type and size in brackets. As usual
Comma sign separates each column. For Example, suppose you

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 26


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

want to add column comm in emp_master, then you have to perform the following

command.

 SQL>ALTER TABLE Passenger ADD FOREIGN KEY (PNR_NO) REFERENCES


Reservation(PNR_NO);

Table altered.

 SQL> ALTER TABLE Cancellation ADD FOREIGN KEY (PNR_NO) REFERENCES


Reservation(PNR_NO);

Table altered.

SQL> alter table Ticket modify tiketnonumber(10);

Table altered.

Deletion of Column

Till Oracle8 it is not possible to remove columns from a table but in Oracle8i, drop option is used
withAlter table_ when you want to drop any existing column.

Alter table <table_name> drop column <column name>;

Using above command you cannot drop more than one column at a time.

For Example, suppose you want to delete just before created column comm from the emp_master, then
you have to apply following command.

SQL>Alter Table Emp_master drop column comm; Table


altered.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 27


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Dropping column is more complicated than adding or modifying a column, because of the additional
work that Oracle has to do. Just removing the column from the list of columns in the table actually
recover the space that was actually taken up by the column values that is more complex, and potentially
very time- consuming for the database. For this reason, you can drop a column using unused clause.
Column can be immediately remove column b y drop clause, the action may impact on performance or
one make marked column as unused using unused caluse, there will be no impact on performance. When
unused caluse is used the column can actually be dropped at a later time when the database is less
heavily used. One can marked column as a unused using :

Alter table <table_name> set unused column <column name>;

For Example,

SQL>Alter Table Emp_master set unused column comm;

Table altered.

Making a column as Unused_ does not release the spcace previously used by the colum, until you drop
the unused columns. It can be possible using:

Alter table <table_name> drop unused columns;

Once you have marked column as unused_ you cannot access that column

You can drop multiple columns at a time using single command as per follows

Alter table <table_name> drop (Column1, Column2,_);

The multiple columns name must be enclosed in parentheses.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 28


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Modification in Column

Modify option is used with Alter table_ when you want to modify any existing column.

If you want to

modify data type or size of more than one column then just write column name, data type and size in
brackets and each column is separated by comma sign as per follows:

Alter table <table name> modify (column1 datatype,・_);

For Example, if you want to change size of salary column of emp_master the following command is
performed.

SQL> Alter table emp_master modify salary number(9,2);

Table altered.

It will change size of salary column from 7 to (9,2).

When you want to decrease the size of column, table must be empty. If table has any rows then it will
not allow decrement in the column width.

Truncate Table

If there is no further use of records stored in a table and the structure is required then only data can be
deleted using Truncate command. Truncate command will delete all the records permanently of specified
table as follows.

Truncate table <table name> [Reuse Storage];

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 29


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Example

Following command will delete all the records permanently from the table.

SQL>Truncate Table Emp_master;

Or

SQL>Truncate Table Emp_master Reuse Storage;

Table truncated.

Alter table <table_name> drop (Column1, Column2,_);

The multiple columns name must be enclosed in parentheses.

Modification in Column

Modify option is used with Alter table_ when you want to modify any existing column.

If you want to

modify data type or size of more than one column then just write column name, data type and size in
brackets and each column is separated by comma sign as per follows:

Alter table <table name> modify (column1 datatype,・_);

For Example, if you want to change size of salary column of emp_master the following command is
performed.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 30


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

SQL> Alter table emp_master modify salary number(9,2);

Table altered.

It will change size of salary column from 7 to (9,2).

When you want to decrease the size of column, table must be empty. If table has any rows then it will
not allow decrement in the column width.

Truncate Table

If there is no further use of records stored in a table and the structure is required then only data can be
deleted using Truncate command. Truncate command will delete all the records permanently of specified
table as follows.

Truncate table <table name> [Reuse Storage];

Example

Following command will delete all the records permanently from the table.

SQL>Truncate Table Emp_master;

Or

SQL>Truncate Table Emp_master Reuse Storage;

Table truncated.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 31


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

EXPERIMENT -7

QUERYING

AIM: practice queries (along with sub queries) using ANY, ALL, IN, EXISTS, NOT EXIST, UNION,
INTERSECT, Constraints etc.

Practice the following Queries:


1. Display unique PNR_No of all passengers.

2. select Ppno from Passenger;

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 32


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

3. Display all the names of male passengers


select Name from Passenger where Sex='Male';

4. Display the ticket numbers and names of all the passengers.


select Ticket_NO, Name from Passenger

5. Find the ticket numbers of the passengers whose name start with 'r' and ends with ‘h'.
select Ticket_NO from Passenger where Name like'K%'and name like'%N';

6. Find the names of passengers whose age is between 30 and 45.


select Name from Passenger where age between 30 and 45;

7. Display all the passenger’s names beginning with 'A'


select Name from Passenger where Name like 'r%';

8. Display the sorted list of passengers names.


select Name from Passenger ORDER BY Name;

EXPERIMENT-9

AIM: QUERYING practice queries using Aggregate functions (COUNT, SUM, AVG, MAX,and
MIN), GROUP BY, HAVING and Creation and dropping of VIEWS.

1. Write a Query to display the information present in the Passenger and cancellation tables. Hint:
Use UNION Operator.

select * from Reservation UNION select * from Cancellation;

2. Display the number of days in a week on which the 9W01 bus is available.:
Find number of tickets booked for each PNR_No using GROUP BY CLAUSE.
Hint: Use GROUP BY on PNR_No.

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 33


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Select PNR_NO,sum(No_of_seats) from Reservation group by PNR_NO;

3. Find the distinct PNR numbers that are present.

select * from Reservation UNION select * from Cancellation;

4. Find the number of tickets booked by a passenger where the number of seats is greater than 1.
Hint: Use GROUP BY, WHERE and HAVING CLAUSES.

Select p.name , r.No_of_seats from Reservation r , passenger p where p.pnr_no =


r.pnr_no group by r.pnr_no having r.No_of_seats> 1;

5. Find the total number of cancelled seats.

select sum(No_of_seats) from Cancellation;

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 34


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

Entire documentation should be in Times New Roman

Main headings should be in font size 16

Sub headings should be in font size 14

Normal text should be in font size 12

Exp No.: XXX (font size 16)

AIM: (font size 14)

Algorithm: (14) or introduction about experiment

Source code: (font size 14)

Output :(font size 14)

Viva questions :(font size 14)

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 35


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

EXPERIMENT-1 (font size 16)


AIM:(font size14 ) To print the capital of country from HTML page that contains a selection box
with a list of 5 countries. When the user selects a country, its capital should be printed next to the list.
Add CSS to customize the properties of the font of the capital (color, bold and font size)

PROCEDURE OR ALGORITHM: To execute a PHP program:


1.Open XAMPP control Panel then start Apache Server and Mysql.
2.Open Notepad++ and Save the php program in htdocs folder of XAMPP.
3.To run the php file open the browser and type the following URL localhost:90/directory
name/filename

SOURCE CODE:
import java.io.*;
importjavax.xml.parsers.*;
import org.w3c.dom.*;
importorg.xml.sax.*;
public class Parse {
public static void main(String[] arg) {
try { System.out.println("enter the name of xml document");
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
String file_name=input.readLine();
File fp=new File(file_name);
if(fp.exists())
{ try { DocumentBuilderFactoryFactory_obj=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=Factory_obj.newDocumentBuilder();
InputSourceip_src=new InputSource(file_name);
Document doc=builder.parse(ip_src);
System.out.println(file_name+" is well-formed!"); } catch(Exception e)

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 36


DEPT OF INFORMATION TECHNOLOGY DATA BASE MANAGEMENT SYSTEM

{ System.out.println(file_name+" isn't well-formed!");


System.exit(1); } }
else { System.out.print("file not found!");
} } catch(IOException ex) { ex.printStackTrace(); } }}

OUTPUT:
4

VIVA QUESTIONS:
1. How do you insert a comment in html?

2. What are some of the common lists that can be used when designing a page?

3. How do you create links to sections within the same page?

4. Does a hyperlink apply to text only?

MAHAVEER INSTITUTE OF SCIENCE & TECHNOLOGY 37