Lab No3
Lab No3
LAB - 3
Reg. #: UW-23-SW-BS-023
Semester:2nd
Date: 15/03/2024
1|Page
Database Lab
Task 1:
Create following Movie table and insert data into the tables.
DDL
CREATE TABLE movie
(
mID INT PRIMARY KEY NOT NULL,
Title VARCHAR(30) NOT NULL,
Year INT,
Director VARCHAR(50)
);
DML
INSERT INTO Movie VALUES
(101, "Gone with the Wind", 1939, "Victor Fleming"),
(102, "Star Wars", 1977, "George Lucas "),
(103, "The Sound of Music", 1965, "Robert Wise"),
(104, "E.T.", 1982, "Steven Spielberg"),
(105, "Titanic", 1997, "James Cameron"),
(106, "Snow White", 1937, NULL),
(107, "Avatar", 2009, "James Cameron"),
(108, "Raiders of the Lost Ark", 1981, "Steven Spielberg");
Schema
SELECT * FROM Movie;
Task 2;
DDL
CREATE TABLE Review (
rID INT PRIMARY KEY NOT NULL,
Name VARCHAR(35)
);
2|Page
Database Lab
DML
INSERT INTO Review VALUES
(201, "Sarah Martinez"),
(202 , "Daniel Lewis"),
(203, "Brittany Harris"),
(204, "Mike Anderson"),
(205, "Chris Jackson"),
(206 , "Elizabeth Thomas"),
(207, "James Cameron"),
(208, "Ashley White");
Schema
SELECT * FROM Review;
Task 3
DDL
CREATE TABLE Rating (
rID INT,
FOREIGN KEY (rID) REFERENCES Review(rID),
mID INT,
FOREIGN KEY (mID) REFERENCES Movie(mID),
Stars INT NOT NULL,
Date DATE
);
DML
INSERT INTO Rating VALUES
(201, 101, 2, '2011-01-22'),
(201, 101, 4, '2011-01-27 '),
(202, 106, 4, NULL),
(203, 103, 2, '2011-01-20'),
(203, 108, 4, '2011-01-12'),
(203, 108, 2, '2011-01-30'),
(204, 101, 3, '2011-01-09'),
(205, 103, 3, '2011-01-27'),
(205, 104, 2, '2011-01-22'),
(205 , 108 , 4 , NULL),
(206, 107, 3, '2011-01-15'),
(206, 106, 5, '2011-01-19'),
(207, 107, 5, '2011-01-20'),
(208, 104, 3, '2011-01-02');
3|Page
Database Lab
Schema
SELECT * FROM Rating;
Procedure:
i. start.
ii. Open MySQL Workbench and connect to your computer or a server.
iii. Create a new database by typing "CREATE DATABASE" followed by your
desired database name.
iv. Inside that database, make a table by typing "CREATE TABLE" and then the
table name. Define the names of the columns and the type of data they will
hold.
v. Set any rules for the data, like not allowing empty values or specifying a
maximum length.
vi. Choose one column as the primary key, which will uniquely identify each row.
vii. Insert your data into the table using "INSERT INTO," followed by the table
name and the values you want to add.
viii. Be sure to list the values in the same order as the columns were defined when
creating the table.
ix. To view the contents of your table, use "SELECT * FROM" followed by the
table name.
x. All done.
4|Page
Database Lab
Comments;
1. We delved into the core concepts of database management, particularly focusing on two
crucial aspects.
from.
4. By constructing and populating MySQL tables with movie-related data, we've laid the
groundwork for future analyses and insights, underscoring the power of databases
Conclusion;
Understanding DDL commands is fundamental for anyone working with databases. The
ability to create, alter, rename, and truncate database objects allows for efficient
effectively, enabling tasks such as retrieving specific information, modifying existing data,
or removing obsolete records. By mastering both DDL and DML, individuals can
effectively design, maintain, and utilize databases to support various applications and
business needs.
__________________END________________
5|Page