Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Assignment No.

02
SEMESTER Spring 2023
CS403- Database Management System

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).

To create a new database in SQL Server, you can use the following SQL statement:

CREATE DATABASE bc220007761;

Task 2:

Create tables Stadium, MatchSchedule, and Block

To create the Stadium table, MatchSchedule table, and Block table in the database created in Task 1,
you can use the following SQL statements:

-- Create Stadium table


CREATE TABLE Stadium (
StadiumID INT PRIMARY KEY,
StadiumName VARCHAR(50),
Capacity INT
);
-- Create MatchSchedule table
CREATE TABLE MatchSchedule (
MatchID INT PRIMARY KEY,
MatchDate DATE,
StartTime TIME,
EndTime TIME,
StadiumID INT,
Team VARCHAR(50);
FOREIGN KEY (StadiumID) REFERENCES Stadium (StadiumID)
);

-- Create Block table


CREATE TABLE Block (
BlockID INT PRIMARY KEY,
BlockName VARCHAR(50),
Charges DECIMAL(10, 2),
Capacity INT,
StadiumID INT,
FOREIGN KEY (StadiumID) REFERENCES Stadium (StadiumID)
);
-- Create Team table
CREATE TABLE Team (
TeamID INT PRIMARY KEY,
TeamName VARCHAR(50)
);
-- Create TeamMatchSchedule table as the junction table
CREATE TABLE TeamMatchSchedule (
TeamID INT,
ScheduleID INT,
PRIMARY KEY (TeamID, ScheduleID),
FOREIGN KEY (TeamID) REFERENCES Team (TeamID),
FOREIGN KEY (ScheduleID) REFERENCES MatchSchedule (ScheduleID)
);
Task 3:

Insert 2 records in each table

To insert two records into each table, you can use the following SQL statements as examples:

-- Insert records into Stadium table


INSERT INTO Stadium (StadiumID, StadiumName, Capacity)
VALUES (100, 'Stadium ALI', 1000),
(200, 'Stadium BILAL', 1500);

-- Insert records into MatchSchedule table


INSERT INTO MatchSchedule (MatchID, MatchDate, StartTime, EndTime, StadiumID)
VALUES (101, '2022-06-15', '11:00:00', '12:00:00', 100),
(201, '2021-06-16', '16:30:00', '19:30:00', 200);

-- Insert records into Block table


INSERT INTO Block (BlockID, BlockName, Charges, Capacity, StadiumID)
VALUES (102, 'Block 1A', 50.50, 600, 100),
(202, 'Block 2B', 75.60, 850, 200);
-- Insert records into Team table
INSERT INTO Team (TeamID, TeamName)
VALUES (1, 'Team A'),
(2, 'Team B');
Task 4:

SQL Statements for the given tasks

1. Display name and capacity of all blocks.


SELECT BlockName, Capacity FROM Block;

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


SELECT AVG(Charges) AS AverageCharges FROM Block;
3. Remove column StadName from the Stadium table.
ALTER TABLE Stadium
DROP COLUMN StadName;

You might also like