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

DDL and DML

The document provides a scenario where the user must create the database and tables for an online movie rental store based on metadata provided in an Excel file. The deliverables are: 1) A 700 word report differentiating DDL and DML, focusing on techniques like CREATE, ALTER for DDL and INSERT, UPDATE, DELETE, SELECT for DML. 2) Detailed SQL queries to create the tables and insert sample data based on the provided metadata. The document provides criteria for assessment focusing on identification of techniques and quality of report.

Uploaded by

Hamza Saleem
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

DDL and DML

The document provides a scenario where the user must create the database and tables for an online movie rental store based on metadata provided in an Excel file. The deliverables are: 1) A 700 word report differentiating DDL and DML, focusing on techniques like CREATE, ALTER for DDL and INSERT, UPDATE, DELETE, SELECT for DML. 2) Detailed SQL queries to create the tables and insert sample data based on the provided metadata. The document provides criteria for assessment focusing on identification of techniques and quality of report.

Uploaded by

Hamza Saleem
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Scenario:

You are required to create a database for the Online Movie Rental Store. You are asked to write Create
Database and Create Table statements to create the physical structure of the requirements given in the attached
excel sheet. You are also required to choose the appropriate data types, select primary keys and foreign keys
within the different tables according to the data provided in the meta-data file (Excel file is given). You are
asked to insert at least 4 records in each table (as part of DML part).

Deliverable:

1. A detailed report (approx. 700 words) to differentiate between the DDL and DML. (10 marks)
2. Detail SQL Queries (for attached scenario) (10 marks)

Note: The work should be described in your own words. Avoid Plagiarism.

Criteria:

Assessment criteria
Grades E/F D C B A
-Identify a few of the - Identify some of the - Identify most of the - Identify all of the
-Identify very few/none of the most
most significant most significant most significant most significant
significant techniques.
techniques. techniques with techniques. techniques with proper
Weak report. Basic contents and lacks
Reasonable report. respective references. Good report. examples.
flow, structure and understanding, or,
Reasonable Satisfactory report. Overall good Excellent report.
no/poor, irrelevant report. Poor
presentation and Good presentation and presentation and Well-structured and
structure and presentation.
structure. structure. structure. presented.
PART(A): A detailed report (approx. 700 words) to differentiate between the DDL and
DML.

Introduction:
SQL Commands are divided in to two main groups Data Definition Language (DDL) and Data
Management Language (DML). It seems that Data-Definition Language and Data Manipulation
Language are different languages, but they are not different languages. Both Languages are
used in database systems. DDL statements are like a computer programming language for
defining data structures, especially database. DDL deals with the database Schemas and
Description that how data can be stored or reside in the database, hence in this case CREATE
TABLE, ALTER TABLE.ETC belongs to DDL. Whereas Data Management Language is used
to manage data which is stored into the Database. Like how we can Retrieve the Data, insert the
data into the Database and in context of SQL it is a popular data manipulation language which
is used to retrieve and manipulate data in a relational database. Now we briefly discuss
descriptive language and Data Manipulation language in SQL database.

DDL:
DDL stand for Data Definition Language it is used to create/modify database structures like
schemas, view, indexes, tables. It is also known as Data Description Language. Data Definition
Language is used to define attributes in the table. DDL is also considered as a subset of
SEQUEL When we define descriptive language in simple terms, we can define DDL language
used to describe data structure in the form table and its attributes. This language is part of the
logical schema. The Data Definition Language also provide the facility to specify some
constraints that would maintain the data consistency in the database. we can say that all the
physical work in the database possible through DDL. SQL statement cannot be rollback in DDL
which mean the process of restoring a database to a previously defined command is not possible
in DDL to recover the data from the error. Following are the Commands that are used by Data
Description Language

1. CREATE: This command is used to create new tables and databases


2. ALTER: This one is used to modify the data in the tables/databases
3. DROP: It is used to delete data from the databases/tables
4. RENAME: This is used to rename the data

Example:
If we want to create the Structure of Database of Company, who sell some computer accessories
we will use the following commands to create database for that company
CREATE Company;

Now we add a table Structure for Company’s Employees.

CREATE TABLE Employees


(
ID char (5),

Name varchar (20),

Email varchar (100),

Phone varchar (11)

);

This is how we use Data Description Language.

DML:
DML Stands for Data Manipulation Language. This is a subset of Structure Query Language.
Basically, this Data Manipulation Language is used to get data in or out from the databases.
Which mean it is used to manage the Data in databases. In simple terms, the use of "data
manipulation" language is a reasonable part of the database in which we set our queries. That is
why Language manipulation Language is part of the Logical Schema. DML is further classified
into two as Procedural and Non and Procedural DMLs. DML is used to add or update data in
the rows and these rows are also known tuples. By using DML Commands, it does not affect
the whole database it just works on the specified tuple and update it. DML is imperative
because without these commands you cannot manipulate the data that why it is very important.
Following are the Commands that are used by Data Description Language

1. INSERT: This Command is used to insert data into the database


2. UPDATE: This Command is used to Update data into the database
3. DELETE: This Command is used to remove data from table/row from the database
4. SELECT: This Command is used to Select column from table

Example:
As we create the structure of the table for Employees on upper example by using DDL.
Now we will add some data in that table using DML

INSERT INTO Employees


VALUES
(
1, ‘Hamza’,’[email protected], 123456’
);

Now if we want to Show that inserted data, we will use the Following DML command:

SELECT * FROM Employees;

If we want to delete some data from table, we will use the following command:

DELETE FROM Employees WHERE ID=1;


Part (B): Detailed SQL QUERIES According to the given Meta-Data:-
Create Table Customer(
name varchar(50),
email varchar (100),
phone varchar(12),
totalPurchase numeric,
Primary Key (email)
);

INSERT INTO Customer


VALUES
('Hamza', '[email protected]', '123244', 300 ),
('Saleem', '[email protected]', '5543545', 30 ),
('Sadiq', '[email protected]', '7554645353', 650 ),
('Ali', '[email protected]', '234738426', 450 );

Create Table Video


(
vID varchar,
name varchar(200),
yearr numeric (4),
cost numeric NULL,
genre varchar (200),

Primary Key (vID)


);

INSERT INTO Video


VALUES
('0','Shazam!',2019,50,'Action/Comedy'),
('1','Avengers EndGame',2019,100,'Action/Sci-fi'),
('2','Spider-Man: Far From Home',2019,500,'Action/Adventure'),
('3','Wonder Woman 1984',2020,1000,'Action/Fantasy ');

Create Table Actor


(
aID varchar,
name varchar(50),
dob date NULL,
Primary Key (aID)
);
INSERT INTO Actor
VALUES
(0,'Zachary Levi','1980-11-29'),
(1,'Robert Downey, Jr.','1965-4-4'),
(2,'Tom Holland','1996-6-1'),
(3,'Gal Gadot','1985-4-20');
Create Table Price
(
priceCode varchar (50) ,
cost numeric,

Primary Key (priceCode)

);
INSERT INTO Price
VALUES
('codecx281',20),
('codecx632',35),
('codecx342',50),
('acodecx98',100);

Create Table Rents


(
email varchar(100),
vID varchar(1),
priceCode varchar(50),
rentalFee numeric,
lateFee numeric,
datee date,
dueDate date,
returnDate date,
Primary Key (email,vID,datee),

Foreign Key(email) References Customer (email),


Foreign Key(vID) References Video (vID),
Foreign Key(priceCode) References Price (priceCode),
);

Insert Into Rents


Values
('[email protected]','2','acodecx98',20,0,'2020-10-19','2020-12-20','2020-12-20'),
('[email protected]','3','codecx281',70,10,'2020-10-10','2020-12-20','2021-12-1'),
('[email protected]','1','codecx342',400,700,'2020-10-12','2020-12-20','2020-12-2'),
('[email protected]','0','codecx632',20,0,'2020-10-20','2020-12-20','2021-1-21');

Create Table Performs

(
vID varchar(1),
aID int,
Primary Key (vID,aID),
Foreign Key (vID) References Video(vID),
Foreign Key (aID) References Actor(aID),
);

You might also like