DBMS Ii
DBMS Ii
Lab Sheet-2: Use of SQL Data Definition Language (DDL) to create the COMPANY Database and
create following tables in MySQL XAMPP
Lab Sheet-3: Use Draw.io CASE Tool to draw the E-R database of COMPANY database and import in
word document
Lab Sheet-4: Prepare the requirements (miniworld) of Patan Multiple Campus Library and draw E-R
diagrams and their relational database Tables.
Lab Sheet-5: Prepare the requirements (miniworld) of Students database of Patan Multiple Campus
BTI Department. Draw E-R diagrams and their relational database Tables.
Lab Sheet-6: Use of SQL Constraints - The following constraints are commonly used in SQL
Lab Sheet-8: What are domain constraints? Explain the difference between PRIMARY and UNIQUE
constraints. Use the following constraints to create an EMPLOYEE table.
Lab Sheet-9: Create all the COMPANY Database Tables with all various constraints (Primary, Domain,
Foreign and Referential integrity) and insert 5 records in each tables and then use the following SQL
commands
2
Lab Sheet-1: How to Create a Database and various Tables using CMD in MySQL XAMPP.
Write the syntax and explain.
3. Creating a Database
Before creating tables, you need to select the database you just created:
USE database_name;
5. Creating Tables
3
Example:
CREATE TABLE students (
student_id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
birth_date DATE,
gender ENUM('M', 'F'),
enrollment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Example:
Example:
4
Lab Sheet-2:Use of SQL Data Definition Language (DDL) to create the
COMPANY Database and create following tables in MySQL XAMPP.
Dname VARCHAR(50),
Dnumber INT PRIMARY KEY,
Mgr_ssn INT,
Mgr_start_date DATE,
FOREIGN KEY (Mgr_ssn) REFERENCES EMPLOYEE(Ssn) );
Pname VARCHAR(50),
Pnumber INT PRIMARY KEY,
Plocation VARCHAR(100),
Dnum INT,
FOREIGN KEY (Dnum) REFERENCES DEPARTMENT(Dnumber) );
5
-- Create WORKS_ON Table
Lab Sheet-3: Use Draw.io CASE Tool to draw the E-R database of COMPANY database and
import in word document.
6
Lab Sheet-4: Prepare the requirements (miniworld) of Patan Multiple Campus Library and
draw E-R diagrams and their relational database Tables.
Books Table : Would connect Student_name and Book_ISBN. It shows the details of the
books.
1.BOOK
7
ISBN Title NO_copies Author Publication
2.Student
3.Department
BIT Patan
CSIT Patan
8
Lab Sheet -5: Prepare the requirements (miniworld) of Students database of Patan Multiple
Campus BIT Department. Draw ER-Diagram and their relational database Tables.
⮚ Student Database contains Student. Each Student table contains roll no, name, address,
date of birth, sex and courses they take.
⮚ Course contains id which is course code, name, credit hour.
⮚ Lecturers contain id, name, courses that they teach. Lecturers may teach many students
and teach many courses in every new semester.
9
1. Teacher
Teacher_ID Teacher_Name Course_ID
101 Ram Lakhan Pal BIT201
102 Kshavraj Hari BIT202
103 Surya Man Singh BIT203
2. STUDENT
Student_ID Student_Name Course_ID
79020032 Ram Thapa BIT201
79020005 Dishant Paneru BIT202
79020001 Utsab Pradhan BIT203
79002008 Prashant Bandari BIT204
3. Department
Course_ID Course_Name
1 BIT
2 Bsc CSIT
3 BCA
4 BBA
4. SUBJECTS
Subject_ID Subject_Name
201 DSA
202 DBMS
10
203 NM
204 OS
205 POM
Lab Sheet -6:Use of SQL Constraints – The following constraints are commonly
used in SQL.
1. NOT NULL – Ensures that a column cannot have a NULL value.
To verify if NOT NULL has been successfully applied we describe the table.
11
As we can clearly see Ssn is not a null therefore this field cannot be null.
In the image below, UNI in Key represents that the field is UNIQUE
12
PRI represents that the key is PRIMARY KEY in employee table
Employee Table
13
Here MUL represents FOREIGN KEY.
This is how we use CHECK constraints. In this table students with age 18
or greater can only be inserted and if the condition is not met it returns
error.
14
Lab Sheet -7:What is Referential Integrity?
Employee Table
15
2. CHECK – Ensures that the values in a column satisfies a specific
condition.
This is how we use CHECK constraints. In this table students with age 18
or greater can only be inserted and if the condition is not met it returns
error.
16
Lab Sheet -8: What are Domain Constraints? Explain the difference between
PRIMARY KEY and UNIQUE constraints. Use the constraints to create an
EMPLOYEE table.
17
As we can clearly see Ssn is not a null therefore this field cannot be null.
In the image below, UNI in Key represents that the field is UNIQUE
18
PRI represents that the key is PRIMARY KEY in employee table
19
To add a FOREIGN KEY we first create 2 different tables with their
respective PRIMARY KEYS and later ALTER the table to add
FOREIGN KEY.
Employee Table
20
3. CHECK – Ensures that the values in a column satisfies a specific
condition.
This is how we use CHECK constraints. In this table students with age 18
or greater can only be inserted and if the condition is not met it returns
error.
Lab Sheet -9:Create all the COMPANY Database Tables with all various
constraints (Primary, Domain, Foreign and Referential Integrity) and Insert 5
records in each table and then use the following SQL commands.
21
Employee Table
Department Table
22
Project Table
Dependent Table
Dept_Location Table
23
Works_On Table
24
ii. For every project located in ‘Kathmandu’, list the project
number, the controlling department number, manager’s last
name, address and birthdate.
ii. For each project, retrive the project number, project name
and the number of employees who work on that project.
25
9.3. Use of HAVING clause
i. For each project on which more than two employees work,
retrieve the project number, project name and the number of
employees who work on that project.
26