0% found this document useful (0 votes)
42 views7 pages

Cs403 Assignment Solution 1 Fall 2023

This document contains the solution to an assignment on database management systems. It includes: 1. SQL statements to create a database, tables, and insert sample records. Tables are created for Stadium, MatchSchedule, and Block with attributes, data types, and primary keys defined. 2. Sample data is inserted into each table with 2 records each. 3. SQL statements are provided to query the database by selecting block names and capacities, calculating the average block charges, and removing a column from the Stadium table.

Uploaded by

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

Cs403 Assignment Solution 1 Fall 2023

This document contains the solution to an assignment on database management systems. It includes: 1. SQL statements to create a database, tables, and insert sample records. Tables are created for Stadium, MatchSchedule, and Block with attributes, data types, and primary keys defined. 2. Sample data is inserted into each table with 2 records each. 3. SQL statements are provided to query the database by selecting block names and capacities, calculating the average block charges, and removing a column from the Stadium table.

Uploaded by

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

lOMoARcPSD|20397872

CS403 assignment solution 1 fall 2023

Database Management Systems (Virtual University of Pakistan)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by rehan mughal ([email protected])
lOMoARcPSD|20397872

VU ID: BC 200205775
NAME: MUHAMMAD ASIM
CS403- Database Management System
ASSIGNMENT NO. 2 SOLUTION SPRING 2023

Task 1:
Write SQL statement to create a new database in SQL Server by your VU ID (sample screenshot
is provided on the last page of this file).
SOLUTION:
SQL statement to create a new database in SQL Server:
--CREATE DATABASE bc200205775;

Task 2:
Write SQL statements for the following:
 Create tables: Stadium, MatchSchedule and Block in database created in Task 1.

Downloaded by rehan mughal ([email protected])


lOMoARcPSD|20397872

 For each table, you have to define all attributes/columns given in ERD with appropriate
data types.
 You are also required to define Primary key of each table.
 Transform multi-valued attribute.
 Map all relationships and add foreign keys in appropriate tables according to
relationships types.

SOLUTION:
SQL statements to create tables:
1. Stadium Table:

USE bc200205775;
CREATE TABLE Stadium (
StadiumID INT PRIMARY KEY,
StadiumName VARCHAR(100),
Location VARCHAR(100),
Dimension VARCHAR(50)
);
2. MatchSchedule Table:

USE bc200205775
CREATE TABLE MatchSchedule (
ScheduleID INT PRIMARY KEY,
MatchDate DATE,
MatchTime TIME,
MatchDay VARCHAR(20),
Teams VARCHAR(100)
);

Downloaded by rehan mughal ([email protected])


lOMoARcPSD|20397872

3. CREATE TABLE Block (

BlockID INT PRIMARY KEY,


BName VARCHAR(100),
Capacity INT,
Charges DECIMAL(10,2),
BColor VARCHAR(20),
StadiumID INT,
FOREIGN KEY (StadiumID) REFERENCES Stadium (StadiumID)
);

Task 3:
Write SQL Statements to insert 2 records in each table.

Downloaded by rehan mughal ([email protected])


lOMoARcPSD|20397872

SOLUTION:
SQL Statements to insert 2 records in each table:
1. Inserting records in the Stadium Table:

USE bs200205775;
INSERT INTO Stadium (StadiumID, StadiumName, Location, Dimension)
VALUES (1, 'Stadium A', 'Location A', 'Dimension A'),
(2, 'Stadium B', 'Location B', 'Dimension B');
2. Inserting records in the MatchSchedule table:

USE bs200205775;
INSERT INTO MatchSchedule (ScheduleID, MatchDate, MatchTime,
MatchDay,Teams)
VALUES (1, '2023-07-10', '14:30:00', 'Sunday', 'Team A vs Team B'),
(2, '2023-07-12', '18:00:00', 'Tuesday', 'Team C vs Team D');

3. Inserting records in the Block table:

USE bs200205775;
INSERT INTO Block (BlockID, BName, Capacity, Charges, BColor, StadiumID)
VALUES (1, 'Block 1', 100, 10.50, 'Red', 1),
(2, 'Block 2', 150, 8.75, 'Blue', 1);

Downloaded by rehan mughal ([email protected])


lOMoARcPSD|20397872

Task 4:
Write SQL Statements to:
1. Display name and capacity of all blocks.
USE bc200205775
SELECT BName, Capacity
FROM Block;

2. Display Average charges/amount of blocks using appropriate function.


USE bc200205775
SELECT AVG(Charges) AS AverageCharges
FROM Block;

3. Remove column StadName from Stadium table.


USE bc200205775
ALTER TABLE Stadium
DROP COLUMN StadiumName;

Downloaded by rehan mughal ([email protected])


lOMoARcPSD|20397872

Downloaded by rehan mughal ([email protected])

You might also like