Lab Work-2080
Lab Work-2080
Lab Sheet-1: How to Create a Database and various Tables using CMD in MySQL XAMPP. Write
the syntax and explain. .............................................................................................................. 2
Lab Sheet-2: Use of SQL Data Definition Language (DDL) to create the COMPANY Database
and create following tables in MySQL XAMPP. .......................................................................... 2
Lab Sheet-3: Use Draw.io CASE Tool to draw the E-R database of COMPANY database nd
import in word document. ......................................................................................................... 2
Lab Sheet-4: Prepare the requirements (miniworld) of Patan Multiple Campus Library and
draw E-R diagram and their relational database Tables. ............................................................ 2
Lab Sheet-5: Prepare the requirements (miniworld) of Students database of Patan Multiple
Campus BIT Department . Draw E-R diagram and their relational database Tables. .................. 2
Lab Sheet-6: Use of SQL Constraints – The following constraints are commonly used in SQL ... 2
Lab Sheet-7: What is Referential Integrity? .............................................................................. 2
Lab Sheet-8: What is domain constraints? Explain the difference between PRIMARY and
UNIQUE constraunts. Use following constraints to create EMPLOYEE table. ............................. 5
Lab Sheet-9: Create all the COMPANY Database Tables with all various constrains (Primary,
Domain, Foreign and Referential integrity) and insert 5 records in each tables and then use the
following SQL commands. .......................................................................................................... 6
Lab Sheet-9_1: Use of SELECT and FROM clauses. .................................................................. 6
Lab Sheet-9_2 Use of SELECT, FROM and WHERE clauses....................................................... 6
Lab Sheet-9_3: Use of GROUP BY clause ................................................................................. 6
Lab Sheet-9_4: Use of HAVING clause .................................................................................... 6
Lab Sheet-9_5: Use of ORDER BY clause ................................................................................. 6
Lab Sheet-1: How to Create a Database and various Tables using CMD in MySQL XAMPP. Write
the syntax and explain.
Lab Sheet-2: Use of SQL Data Definition Language (DDL) to create the COMPANY Database and
create following tables in MySQL XAMPP.
EMPLOYEE(Ssn,Fname,Mnit,Lname,Bdate,Address,Sex,Salary,Super_ssn,Dno)
DEPARTMENT(Dname,Dnumber,Mgr_ssn,Mgr_start_date)
PROJECT(Pname,Pnumber,Plocation,Dnum)
DEPENDENT(Essn,Dependent_name,Sex,Bdate,Relationship)
DEPT_LOCATIONS (Dnumber,Dlocation)
WORKS_ON (Essn,Pno,Hours)
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 diagram and their relational database Tables.
Lab Sheet-5: Prepare the requirements (miniworld) of Students database of Patan Multiple
Campus BIT Department . Draw E-R diagram and their relational database Tables.
Lab Sheet-6: Use of SQL Constraints – The following constraints are commonly used in SQL
NOT NULL - Ensures that a column cannot have a NULL value
UNIQUE - Ensures that all values in a column are different
PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table
FOREIGN KEY – create foreign key to reference another table column value. The FOREIGN KEY constraint
prevents invalid data from being inserted into the foreign key column
CHECK - Ensures that the values in a column satisfies a specific condition
DEFAULT - Sets a default value for a column if no value is specified
Employees (Id, Name, DepartmentID) where Id is primary Key and DepartmentID is foreign key
Department(Id, Dname) where ID is primary key
CREATE TABLE Employees(
Id INT NOT NULL,
Name varchar(25),
DepartmentID INT,
PRIMARY KEY (Id));
Step2: Alter Employees table to create foreign key with referential integrity
Example as
ALTER TABLE Employees ADD FOREIGN KEY(DepartmentID) REFERENCES Department (Id)
ON DELETE CASCADE
ON UPDATE CASCADE;
Step-3: Now, insert some data into the Employees and Department tables by executing the below SQL
statement.
Step-4: Now, delete the Department whose Id is 10 from the Department table by executing the below SQL
Statement.
Now, you can see the above DELETE statement executed successfully, and further if you notice the employees
whose DepartmentId is 10 are also deleted from the Employees table automatically.
Now, you can see the above UPDATE statement also executed successfully, and further if you notice the
employees whose DepartmentId is 30 are also updated as 40 in the Employees table automatically.
Step-1: First, delete the Employees table by executing the below SQL Statement.
DROP TABLE Employees;
Step-2: Then truncate the Department table and add the three records by executing the below SQL
Statement.
TRUNCATE TABLE Department;
Insert into Department values (10, 'IT');
Insert into Department values (20, 'HR');
Insert into Department values (30, 'INFRA');
Step-3: Now, create the Employees table by executing the below SQL Statement.
CREATE TABLE Employees(
Id INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
DepartmentID INT,
FOREIGN KEY (DepartmentId) REFERENCES Department(Id)
ON DELETE SET NULL
ON UPDATE SET NULL
);
Step-4:Now, insert the following records into the Employees table by executing the below INSERT
Statements.
INSERT into Employees VALUES (101, 'Anurag', 10);
INSERT into Employees VALUES (102, 'Pranaya', 20);
INSERT into Employees VALUES (103, 'Hina', 30);
Step-5: Now, delete the Department whose Id is 10 from the Department table by executing the
below SQL Statement.
Step-1: First, delete the Employees table by executing the below SQL Statement.
DROP TABLE Employees;
Step-2: Then truncate the Department table and add the three records by executing the below SQL
Statement.
TRUNCATE TABLE Department;
Insert into Department values (10, 'IT');
Insert into Department values (20, 'HR');
Insert into Department values (30, 'INFRA');
Step-3:Now, create the Employees table by executing the below SQL Statement.
CREATE TABLE Employees(
Id INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
DepartmentID INT,
FOREIGN KEY (DepartmentId) REFERENCES Department(Id)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
Step-4:Now, insert the following records into the Employees table by executing the below INSERT
Statements.
INSERT into Employees VALUES (101, 'Anurag', 10);
INSERT into Employees VALUES (102, 'Pranaya', 20);
INSERT into Employees VALUES (103, 'Hina', 30);
Step-5: Now, delete the Department whose Id is 10 from the Department table by executing the
below SQL Statement.
DELETE FROM Department WHERE Id = 10;
Now, when you try to execute the above DELETE statement, you will get the following error
message, and the delete operation is rollback.
Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails
(`employeedb`.`employees`, CONSTRAINT `employees_ibfk_1` FOREIGN KEY
(`DepartmentID`) REFERENCES `department` (`Id`))
Lab Sheet-8: What is domain constraints? Explain the difference between PRIMARY and UNIQUE
constraunts. Use following constraints to create EMPLOYEE table.
EMPLOYEE(Ssn,Fname,Mnit,Lname,Bdate,Address,Sex,Salary,Super_ssn,Dno)