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

DBMS_5th Expt (2)

The document outlines the design of a database for managing tourist places, including the creation of an ER-diagram, conversion to a relational model, and normalization of relations. It details the structure of tables for countries, states, tourist places, tourists, tourist emails, and visits, along with sample SQL commands for creating and populating these tables. Additionally, it specifies various queries to extract information about tourist places and visitors based on specific criteria.

Uploaded by

er.poojab45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

DBMS_5th Expt (2)

The document outlines the design of a database for managing tourist places, including the creation of an ER-diagram, conversion to a relational model, and normalization of relations. It details the structure of tables for countries, states, tourist places, tourists, tourist emails, and visits, along with sample SQL commands for creating and populating these tables. Additionally, it specifies various queries to extract information about tourist places and visitors based on specific criteria.

Uploaded by

er.poojab45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

DBMS_Lab_05

Design an ER-diagram for the following scenario, Convert the same into a
relational model, normalize Relations into a suitable Normal form and
then solve the following queries. A country can have many Tourist
places . Each Tourist place is identified by using tourist_place_id,
having a name, belongs to a state, Number of kilometers away from the
02.03.2021 updated 52/ 104 capital city of that state, history. There are
many Tourists visits tourist places every year. Each tourist is
identified uniquely by using Tourist_id, having a Name, age, Country and
multiple emailids. A tourist visits many Tourist places, it is also
required to record the visted_date in the database. A tourist can visit a
Tourist place many times at different dates. A Tourist place can be
visited by many tourists either in the same date or at different dates.
Queries: i. List the state name which is having maximum number of tourist
places.
ii. List details of Tourist place where maximum number of tourists
visited.
iii. List the details of tourists visited all tourist places of the state
“KARNATAKA”.
iv. Display the details of the tourists visited at least one tourist
place of the state, but visited all states tourist places.
v. Display the details of the tourist place visited by the tourists of
all country.

mysql> create database Tourist_places;


Query OK, 1 row affected (0.01 sec)

mysql> USE Tourist_places;


Database changed

mysql> CREATE TABLE Country (


-> Country_ID INT PRIMARY KEY,
-> Country_Name VARCHAR(255) NOT NULL
-> );
Query OK, 0 rows affected (0.20 sec)

mysql> CREATE TABLE State (


-> State_ID INT PRIMARY KEY,
-> State_Name VARCHAR(255) NOT NULL,
-> Country_ID INT,
-> FOREIGN KEY (Country_ID) REFERENCES Country(Country_ID)
-> );
Query OK, 0 rows affected (0.31 sec)

mysql> CREATE TABLE Tourist_Place (


-> Tourist_Place_ID INT PRIMARY KEY,
-> Name VARCHAR(255) NOT NULL,
-> State_ID INT,
-> Distance_From_Capital INT,
-> History TEXT,
-> FOREIGN KEY (State_ID) REFERENCES State(State_ID)
-> );
Query OK, 0 rows affected (0.28 sec)
mysql> CREATE TABLE Tourist (
-> Tourist_ID INT PRIMARY KEY,
-> Name VARCHAR(255) NOT NULL,
-> Age INT,
-> Country_ID INT,
-> FOREIGN KEY (Country_ID) REFERENCES Country(Country_ID)
-> );
Query OK, 0 rows affected (0.39 sec)

mysql> CREATE TABLE Tourist_Email (


-> Email_ID VARCHAR(255) PRIMARY KEY,
-> Tourist_ID INT,
-> FOREIGN KEY (Tourist_ID) REFERENCES Tourist(Tourist_ID)
-> );
Query OK, 0 rows affected (0.24 sec)

mysql> CREATE TABLE Visit (


-> Visit_ID INT PRIMARY KEY,
-> Tourist_ID INT,
-> Tourist_Place_ID INT,
-> Visited_Date DATE,
-> FOREIGN KEY (Tourist_ID) REFERENCES Tourist(Tourist_ID),
-> FOREIGN KEY (Tourist_Place_ID) REFERENCES
Tourist_Place(Tourist_Place_ID)
-> );
Query OK, 0 rows affected (0.27 sec)

mysql> INSERT INTO Country (Country_ID, Country_Name) VALUES


-> (1, 'India'),
-> (2, 'USA');
Query OK, 2 rows affected (0.04 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> INSERT INTO State (State_ID, State_Name, Country_ID) VALUES


-> (1, 'KARNATAKA', 1),
-> (2, 'California', 2),
-> (3, 'New York', 2);
Query OK, 3 rows affected (0.04 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> INSERT INTO Tourist_Place (Tourist_Place_ID, Name, State_ID,


Distance_From_Capital, History) VALUES
-> (1, 'Bengaluru Palace', 1, 10, 'Historical palace in Bengaluru'),
-> (2, 'Hampi', 1, 300, 'Ancient ruins of the Vijayanagara Empire'),
-> (3, 'Yosemite National Park', 2, 320, 'National park known for its
waterfalls and cliffs'),
-> (4, 'Statue of Liberty', 3, 0, 'Famous statue located on Liberty
Island');
Query OK, 4 rows affected (0.04 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> INSERT INTO Tourist (Tourist_ID, Name, Age, Country_ID) VALUES
-> (1, 'Alice', 30, 1),
-> (2, 'Bob', 25, 2),
-> (3, 'Charlie', 28, 1),
-> (4, 'Diana', 35, 2);
Query OK, 4 rows affected (0.03 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> INSERT INTO Tourist_Email (Email_ID, Tourist_ID) VALUES


-> ('[email protected]', 1),
-> ('[email protected]', 2),
-> ('[email protected]', 3),
-> ('[email protected]', 4);
Query OK, 4 rows affected (0.02 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> INSERT INTO Visit (Visit_ID, Tourist_ID, Tourist_Place_ID,


Visited_Date) VALUES
-> (1, 1, 1, '2024-01-10'),
-> (2, 1, 2, '2024-01-12'),
-> (3, 2, 3, '2024-01-15'),
-> (4, 3, 1, '2024-01-20'),
-> (5, 3, 2, '2024-01-22'),
-> (6, 4, 4, '2024-01-25');
Query OK, 6 rows affected (0.09 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> SHOW TABLES;


+--------------------------+
| Tables_in_Tourist_places |
+--------------------------+
| Country |
| State |
| Tourist |
| Tourist_Email |
| Tourist_Place |
| Visit |
+--------------------------+
6 rows in set (0.00 sec)

mysql> DESCRIBE Country;


+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| Country_ID | int(11) | NO | PRI | NULL | |
| Country_Name | varchar(255) | NO | | NULL | |
+--------------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> DESCRIBE State;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| State_ID | int(11) | NO | PRI | NULL | |
| State_Name | varchar(255) | NO | | NULL | |
| Country_ID | int(11) | YES | MUL | NULL | |
+------------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> DESCRIBE Tourist_Place;


+-----------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+--------------+------+-----+---------+-------+
| Tourist_Place_ID | int(11) | NO | PRI | NULL | |
| Name | varchar(255) | NO | | NULL | |
| State_ID | int(11) | YES | MUL | NULL | |
| Distance_From_Capital | int(11) | YES | | NULL | |
| History | text | YES | | NULL | |
+-----------------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> DESCRIBE Tourist;


+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| Tourist_ID | int(11) | NO | PRI | NULL | |
| Name | varchar(255) | NO | | NULL | |
| Age | int(11) | YES | | NULL | |
| Country_ID | int(11) | YES | MUL | NULL | |
+------------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> DESCRIBE Tourist_Email;


+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| Email_ID | varchar(255) | NO | PRI | NULL | |
| Tourist_ID | int(11) | YES | MUL | NULL | |
+------------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> DESCRIBE Visit;


+------------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------+------+-----+---------+-------+
| Visit_ID | int(11) | NO | PRI | NULL | |
| Tourist_ID | int(11) | YES | MUL | NULL | |
| Tourist_Place_ID | int(11) | YES | MUL | NULL | |
| Visited_Date | date | YES | | NULL | |
+------------------+---------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql>

You might also like