Trip-Tea Dbms
Trip-Tea Dbms
Lab File
Lab File
Lab File
PRACTICAL-1
Aim:
To relate the entities appropriately. Apply cardinalities for each relationship. Identify strong and weak entities.
Indicate the type of relationships(total/partial). Incorporate generalization, aggregation, specialization, etc whenever
required.
Theory:
ER model stands for an Entity-Relationship model. It is a high-level data model. This model is used to
define the data elements and relationships for a specified system.
It develops a conceptual design for the database. It also develops a very simple and easy-to-design view of
data.
In ER modeling, the database structure is portrayed as a diagram called an entity-relationship diagram.
The
Component of ER Diagram
1. Entity:
An entity may be any object, class, person, or place. In the ER diagram, an entity can be represented as rectangles.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.
3. Relationship
A relationship is used to describe the relation between entities. A diamond or rhombus is used to represent the
relationship.
3
E-R Model:
1) Bus
BusNo
Source
Destination
CoachType
SCHEMA
Bus: Bus(BusNo:String,Source:String,Destination:String,CoachType:String)
BusNo
Source Destination
CoachType
BUS
2) Ticket
TicketNo
DOJ
Address
ContactNo
BusNo
SeatNo
Source
Destination
SCHEMA
Ticket(TicketNo:String,DOJ:Date,Address:String,ContactNo:Integer,BusNo:String,SeatNo:Integer,Source:String,Dest
ination:String)
Address ContactNo
DOJ
BusNo
Ticket No SeatNo
Source
Destination
Ticket
4
3) Passenger
PassportID
TicketNo
Name
ContactNo
Age
Sex
Address
SCHEMA
Passenger(PassportID:String,TicketNo:String,Name:String,ContactNo:String,Age:Integer,Sex:Character,Address:Stri
ng)
Name Age
Passenger
4) RESERVATION
PNRNo
DOJ
No_Of_Seats
Address
ContactNo
BusNo
SeatNo
SCHEMA
Reservation(PNRNo:String,DOJ:Date,No_of_seats:Integer,Address:String,ContactNo:String,BusNo:String,SeatNo:Int
eger)
Address BusNo
PNRNo DOJ No_of_seats
ContactNo
SeatNo
Reservation
5
5) CANCELLATION
PNRNo
DOJ
SeatNo
ContactNo
Status
SCHEMA
Cancellation(PNRNo:String,DOJ:Date,SeatNo:Integer,ContactNo:String,Status:String)
ContactNo
SeatNo
DOJ Status
PNRNo
Cancellation
6
ADDRESS
DOJ
JOURNEY DATE
PNRNo NO_OF_SEATS
RESERVATION
CONTACT_NO
Asks for
Has a
SOURCE SEX
PASSENGER
Has
a
PNR_NO
User DEPT_NO
CANCELLATION asks for
STATUS
JOURNEY TICKET
_DATE TICKET
CONTACT NO
SEAT_NO ADDRESS
AGE
JOURNEY
SEX
_DATE SOURCE
7
EXPIRY_DATE
MEMBER
2) BOOKS
Author
Book_ID
Title
Price
Available
SCHEMA
Books(Author:String,Book_ID:String,Title:String,Price:Integer,Available:String)
AVAILABLE
AUTHOR
BOOKS
8
3) PUBLISHER
Name
Address
Publ_ID
SCHEMA
Publisher(Name:String,Address:String.Publ_ID:String)
ADDRESS Publ_ID
NAME
PUBLISHER
PUBLISHED
BOOKS PUBLISHER
_BY
PRICE
NAME
EXPIRY_ ADDRESS
AVAILABLE
DATE
MEMBER
_TYPE
BORROWED
_BY MEMBER MEMBER_
DATE
MEMBER_ID
9
PRACTICAL-2
Aim: Create a table called Employee with the following structure.
Theory:
Data Definition Language is used to define the database structure or schema. DDL is also used to specify additional
properties of the data. The database system uses the storage structure and access methods by a set of statements in a
special type of DDL called a data storage and definition language. These statements define the implementation details
of the database schema, which are usually hidden from the users. The data values stored in the database must satisfy
certain consistency constraints.
DQL statements are used for performing queries on the data within schema objects. The purpose of the DQL
Command is to get some schema relation based on the query passed to it. We can define DQL as follows it is a
component of SQL statement that allows getting data from the database and imposing order upon it. It includes the
SELECT statement.
some of the DDL commands: SELECT: It is used to retrieve data from the database.
The SQL commands that deal with the manipulation of data present in the database belong to DML or Data
Manipulation Language and this includes most of the SQL statements. It is the component of the SQL statement that
controls access to data and the database. DCL statements are grouped with DML statements.
DCL includes commands such as GRANT and REVOKE , which mainly deal with the database system's rights,
permissions, and other controls.
Transactions group a set of tasks into a single execution unit. Each transaction begins with a specific task and ends
when all the tasks in the group are completed. If any of the tasks fail, the transaction fails. Therefore, a transaction has
only two results: success or failure.
i)
ii)
iii)
11
iv)
v)
i)
12
ii)
iii)
iv)
v)
i)
ii)
iii)
iv)
v)
14
PRACTICAL-3
Theory:
MySQL Create User
The CREATE USER statement creates new MySQL accounts. It enables authentication, role, SSL/TLS, resource
limit, password management, comment, and attribute properties to be established for new accounts. It also controls
whether accounts are initially locked or unlocked.
If you want to use the Create User, it is required to have a global privilege of Create User statement or the INSERT
privilege for the MySQL system schema. When you create a user that already exists, it gives an error. But if you use,
IF NOT EXISTS clause, the statement gives a warning for each named user that already exists instead of an error
message.
Why we need MySQL Create User?
When the MySQL server installation completes, it has a ROOT user account only to access and manage the databases.
But, sometimes, you want to give the database access to others without granting them full control. In that case, you
will create a non-root user and grant them specific privileges to access and modify the database.
A
a. Create a user and grant all permissions to the user.
b. Insert the any three records in the employee table and use rollback. Check the result.
c. Add primary key constraint and not null constraint to the employee table.
d. Insert null values to the employee table and verify the result
a)
15
b)
c)
16
d)
B.
a) create a user and grant all permissions to the user.
b) Insert values in the department table and use commit.
c) Add constraints like unique and not null to the department table.
d) Insert repeated values and null values into the table.
a)
b)
17
c)
d)
Here in the insert command, we are trying to insert a duplicate value but it is not possible because we define deptno as
a unique constraint.
C.
a) create a user and grant all permissions to the user.
b) Insert values into the table and use commit.
c) Delete any three records in the department table and use rollback.
d) Add constraint primary key and foreign key to the table.
a)
18
b)
c)
19
d)
20
PRACTICAL-4
i)
ii)
iii)
iv)
v)
22
vi)
vii)
viii)
ix) ’
x)
23
xi)
xii)
24
PRACTICAL-5
AIM: MySQL String Functions
THEORY
PRACTICAL-6
F. From the following tables write a SQL query to find the salesperson and customer who reside in the
same city. Return Salesman, cust_name and city. Sample table: salesman
G. From the following tables write a SQL query to find those orders where the order amount exists
between 500 and 2000. Return ord_no, purch_amt, cust_name, city. Sample table: orders
H. From the following tables write a SQL query to find salespeople who received commissions of more
than 12 percent from the company. Return Customer Name, customer city, Salesman, commission.
Sample table: customer
I. Write a SQL statement to make a report with customer name, city, order number, order date, and order
amount in ascending order according to the order date to determine whether any of the existing
customers have placed an order or not.
J. Write a SQL statement to generate a list in ascending order of salespersons who work either for one or
more customers or have not yet joined any of the customers. Sample table: customer
THEORY
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
Different Types of SQL JOINs
• (INNER) JOIN: Returns records that have matching values in both tables
• LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right
table
• RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left
table
• FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table
30
a)
1b)
31
c)
32
D)
e)
33