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

DB LAB Week 5

The document describes a database lab with 3 tasks: 1. Create tables in MySQL Workbench to store employee and department data, and insert sample records. 2. Use command prompt to create a School database with tables for students, subjects, and course enrollments, and insert sample data. 3. Design tables for a CarRentalDB based on an ERD, specifying attributes, primary keys, and foreign key constraints. Write DDL statements to implement the design.

Uploaded by

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

DB LAB Week 5

The document describes a database lab with 3 tasks: 1. Create tables in MySQL Workbench to store employee and department data, and insert sample records. 2. Use command prompt to create a School database with tables for students, subjects, and course enrollments, and insert sample data. 3. Design tables for a CarRentalDB based on an ERD, specifying attributes, primary keys, and foreign key constraints. Write DDL statements to implement the design.

Uploaded by

AASMA WAHEED
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to Database Systems Lab

Week # 5:
 Introduction to MYSQL Workbench tool
 Introduction of command Prompt and it’s complete use
with MYSQL. Introduction to SQL (DDL) Create
database, show database, create table
 Adding constraint in create table (e.g. default, unique,
foreign key (cascade), primary key, not null) Drop
database Desc table (description) Drop table.

Objectives: The objective of this lab is to learn and write SQL DDL statements.
Outcomes: After completing this Lab, students are expected to be able to write SQL DDL
statements of any case study.

Task 1: (Introduction to MySQL workbench Tool)

Create a database “Company” on MySQL workbench tool and perform the following actions:
 Create a Table “Employee”.
 Insert the Columns “EmpID, EmpName, EmpAge, EmpDept” with Datatypes
“INT, VARCHAR(60), INT, VARCHAR(45)”.
 Set “EmpID” as “Primary Key”.
 Add constrain that all columns values of table should be “Not Null”.
 Insert record/values of 4 employees in above created table Employee as given
below:

EmpID EmpName EmpAge EmpDept


1 TOM 25 OPERATIONS
2 EMMA 23 FINANCE
3 BRAD 27 MARKETING
4 BRADLEY 26 IT

 Create another Table “Department”.


 Insert the Columns “DeptID, DeptName, DeptZone” with Datatypes “INT,
VARCHAR(60), VARCHAR(45)”.
 Set “DeptID” as “Primary Key”.
 Add constraint that all columns values of table should be “Not Null”.
 Insert 4 record/values in above the created table Depatment as given below:
DeptID DeptName DeptZone
1 OPERATIONS North
2 FINANCE South
3 MARKETING East
4 IT West

Task 2: (Introduction to Command Prompt and its use with MySQL)

Use command prompt and perform the following task:


 Open MySQL using command.
 View all existing databases using command.
 Create a database “School” using command.
 View all existing databases again using command.
 Create a table “Student” in School database.
o Insert columns “sno, sname, DOB, gender, address” with datatypes
“int(10), varchar(45), date, char(1), varchar(45)”.
o Set sno as primary key.
 Create a table “Subject” in School database.
o Insert columns “subcode, subname, grade with datatypes “varchar(10),
varchar(60), date, int(10)”.
o Set subcode as primary key.
 Create a table “enrolled” in School database.
o Insert columns “stuNo, subNo, marks, enrolldate” with datatypes
“int(10), varchar(10), int(15), date.
o Set stuNo and subNo as primary key.
o Set delete and update cascade constraint.
 Insert 5 records in each above created table.
 View description of all tables.
 Delete Student table.
 Drop Student table.
 Drop School database.
 View all databases again.

Task 3: (Introduction to SQL DDL)

Build a database named ‘CarRentalDB’ using given ERD and perform the following task.
 Make a table for each database relation and list the attributes with types. Make
sure you know the reason why you chose the type of data.
 Define the primary key for each relation. Make sure the primary key identifies
each tuple uniquely.
 What are the foreign key constraints that should be included when creating the
tables in the CarRentalDB database in the following figure?
 Write the appropriate DDL statement to create, describe, delete and drop
database and tables.

You might also like