Está en la página 1de 11

Name: Ashsin Kumar

ID: 2016134192

CIN 623 Database Design and Programming

Major Project

Part 1

Business Rules

1. Customer must open an account before renting a video.


2. Customer must provide valid details such as VOTER CARD and FEA bill.
3. It is the responsibility of the customer to inform the company of any changes in
details; such as customers address.
4. The maximum period of time a movie can be rented is two weeks. After this
period, a fine will be charged depending on the number of days after the due
date.

Creating Tables

Customer Table

CREATE TABLE IF NOT EXISTS Customer

(Customer_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,

Cust_Name VARCHAR(30) NOT NULL DEFAULT '',

Cus_Add VARCHAR(30) NOT NULL DEFAULT '',

PRIMARY KEY (Customer_ID));

Movie_Rental Table

CREATE TABLE IF NOT EXISTS Movie_Rental


Name: Ashsin Kumar
ID: 2016134192

(Rental_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,

Date_Rented Date,

Date_to_be_Rented DATE,

Customer_ID INT,

Movie_ID INT,

PRIMARY KEY (Rental_ID),

FOREIGN KEY (Customer_ID) REFERENCES Customer (Customer_ID),

FOREIGN KEY (Movie_ID) REFERENCES Movie (Movie_ID));

Movie Table

CREATE TABLE IF NOT EXISTS Movie

( Movie_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,

Movie_Name VARCHAR(30) NOT NULL DEFAULT '',

Movie_Type_ID INT,

PRIMARY KEY (Rental_ID),

FOREIGN KEY (Movie_Type_ID) REFERENCES Movie_Type (Movie_Type_ID)

);

Sale Table

CREATE TABLE IF NOT EXISTS Sale

(Invoice_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,


Name: Ashsin Kumar
ID: 2016134192

Amount DOUBLE NOT NULL DEFAULT '',

Rental_ID INT,

PRIMARY KEY (Invoice_ID),

FOREIGN KEY (Rental_ID) REFERENCES Movie (Rental_ID));

Fines Table

CREATE TABLE IF NOT EXISTS Fines

( Rental_ID INT,

Customer_ID INT,

Amount DOUBLE,

Date_Fined DATE,

Remarks VARCHAR(30),

PRIMARY KEY (Rental_ID, Customer_ID),

FOREIGN KEY (Rental_ID) REFERENCES Movie_Rental (Rental_ID),

FOREIGN KEY (Customer_ID) REFERENCES Customer (Customer_ID)

);

Movie_Actor Table

CREATE TABLE IF NOT EXISTS Movie_Actor

(Actor_ID INT,

Movie_ID INT,

Role_ID INT,
Name: Ashsin Kumar
ID: 2016134192

PRIMARY KEY (Actor_ID, Movie_ID),

FOREIGN KEY (Actor_ID) REFERENCES Actors (Actor_ID),

FOREIGN KEY (Movie_ID) REFERENCES Movie (Movie_ID)

);

Movie_Type Table

CREATE TABLE IF NOT EXISTS Movie_Type

(Movie_Type_ID INT,

Movie_Type VARCHAR(30),

PRIMARY KEY (Movie_Type_ID));

Actors Table

CREATE TABLE IF NOT EXISTS Actors

(Actor_ID INT,

Actor_Name VARCHAR(30),

PRIMARY KEY (Actor_ID));

Actors_Role Table

CREATE TABLE IF NOT EXISTS Actor_Role

(Role_ID INT,

Role_Desc VARCHAR(30),
Name: Ashsin Kumar
ID: 2016134192

PRIMARY KEY (Role_ID));

INSERT 3 RECORDS INTO TABLE

Customer Table

INSERT INTO Customer (Customer_ID, Cust_Name, Cus_Add)

VALUES ('3021', 'John Dee', 'Natabua');

INSERT INTO Customer (Cust_Name, Cus_Add)

VALUES ('Avineel Kumar', 'Field 40');

INSERT INTO Customer (Cust_Name, Cus_Add)

VALUES ('Ali Baba', 'Kashmir');

Movie_Rental Table

INSERT INTO Movie_Rental VALUES

('1001', '2018-09-23', '2018-11-16', NULL, NULL),

(NULL, '2018-01-15', '2018-11-02', NULL, NULL),

(NULL, '2018-04-16', '2018-11-30', NULL, NULL);

Movie Table

INSERT INTO Movie (Movie_ID, Movie_Name, Movie_Type_ID)


Name: Ashsin Kumar
ID: 2016134192

VALUES ('19001', 'Bahubali', '14371');

INSERT INTO Movie (Movie_ID, Movie_Name, Movie_Type_ID)

VALUES ('19002', 'transformer', ' 14372');

INSERT INTO Movie (Movie_ID, Movie_Name, Movie_Type_ID)

VALUES ('19003', 'rampage', '14373');

Sale Table

INSERT INTO Sale (Invoice_ID, Amount, Rental_ID)

VALUES ('19001', '20', '2001');

INSERT INTO Sale (Invoice_ID, Amount, Rental_ID)

VALUES ('19002', '5', '2002');

INSERT INTO Sale (Invoice_ID, Amount, Rental_ID)

VALUES ('19003', '15', '2003');

Movie_Actor table

This table consist of all foreign keys which makes table access data from the reference

table.
Name: Ashsin Kumar
ID: 2016134192

Fines Table

INSERT INTO Fines (Rental_ID, Customer_ID, Amount, Date_Fined, Remarks)

VALUES ('10021', '3001', '15', '2018-11-25', 'Not cleared');

INSERT INTO Fines (Rental_ID, Customer_ID, Amount, Date_Fined, Remarks)

VALUES ('10032', '3002', '10', '2018-11-25', 'cleared');

INSERT INTO Fines (Rental_ID, Customer_ID, Amount, Date_Fined, Remarks)

VALUES ('10021', '3003', '5', '2018-11-2', 'Not cleared');

Actors Table

INSERT INTO Actors (Actor_ID, Actor_Name)

VALUES ('19001', 'Aamir Khan');

INSERT INTO Actors (Actor_ID, Actor_Name)

VALUES ('19002', 'Selena Gomez');

INSERT INTO Actors (Actor_ID, Actor_Name)

VALUES ('19003', 'Salman Khan');

Actors_Role Table

INSERT INTO Actor_Role (Role_ID, Role_Desc)

VALUES ('19001', ' Drama);

INSERT INTO Actor_Role (Role_ID, Role_Desc)

VALUES ('19002', 'Supporting ');


Name: Ashsin Kumar
ID: 2016134192

INSERT INTO Actor_Role (Role_ID, Role_Desc)

VALUES ('19003', ' Comedian');

Movie_Type Table

INSERT INTO Movie_Type (Movie_Type_ID, Movie_Type)

VALUES ('14001', ' Action');

INSERT INTO Movie_Type (Movie_Type_ID, Movie_Type)

VALUES ('14002', ' Comedy');

INSERT INTO Movie_Type (Movie_Type_ID, Movie_Type)

VALUES ('14003', ' Drama');

Part 2
1.1. Customer TRIGGER

DROP TABLE Customer

Go

Create Trigger ON Customer BEFORE INSERT ON age

FOR EACH ROW

BEGIN

INSERT INTO Customer(Customer_ID, Cust_Name, Cust_Add, age) VALUES('1001', 'John


Dee', 'Natabua');
Name: Ashsin Kumar
ID: 2016134192

(Customer_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,

Cust_Name VARCHAR(30) NOT NULL DEFAULT '',

Cus_Add VARCHAR(30) NOT NULL DEFAULT '',

age INT NOT NULL DEFAULT;

SELECT age FROM Customer;

If (age) < 18

BEGIN

Echo “Your age is below the required criteria”;

SELECT age FROM Customer;

END

End

2.1. before_Amount_update TRIGGER

CREATE TRIGGER before_Amount_update

BEFORE UPDATE ON Sale

FOR EACH ROW FOLLOWS Movie_Rental

BEGIN

INSERT INTO Sale(INVOICE_ID, Amount, Rental_ID)


Name: Ashsin Kumar
ID: 2016134192

VALUES (“999”,”1247”,”1001”);

END

PART 3
1.1.

CREATE PROCEDURE create staff _table

AS

CREATE TABLE staff _table (

StaffID INT,

FirstName VARCHAR(225),

LastName VARCHAR(225),

);

GO;

CREATE staff_table; (call the procedure)

CREATE PROCEDURE Select staff_table StaffID int


AS
SELECT * FROM staff_table WHERE StaffID = StaffID
GO;

Select staff_table; (call the procedure)

CREATE PROCEDURE count_members


Name: Ashsin Kumar
ID: 2016134192

AS

SELECT COUNT(*)

FROM MEMBERS;

GO;

count_members; (call the procedure)

CREATE PROCEDURE staff


AS
SELECT memberID, firstname, lastname, age
from staff
where age <=25
GO;

CREATE PROCEDURE total_sales


AS
SELECT Invoice_ID ,Amount, Rental_ID
FROM dvd_rental_sale
WHERE total_sales = total_sales
GO;