Department of Electronics and Telecommunication Engineering Academic Year: 2026-27 Lab Manual Class and Semester: - TE, V Course Name: - Database Management System Lab Course Code : - CEMDML501 INDEX EXPT. NO. TITLE OF EXPERIMENT COs 1 Identify the case study and detail statement of problem. Design an Entity-Relationship (ER) / Extended Entity-Relationship (EER) Model 1 2 Mapping ER/EER to Relational schema model. 1 3 Create a database using Data Definition Language (DDL) and apply integrity constraints for the specified System 2 4 Apply DML Commands for the specified system 2 5 Perform Simple queries, string manipulation operations and aggregate functions. 3 6 Implement various Join operations. 4 7 Perform Nested and Complex queries 5 8 Perform DCL and TCL commands 2 9 Implement procedure and functions 5 10 Implementation of Views and Triggers 6 11 Apply arithmetic, logical, Comparison and logical Operators 4 12 Perform Set operators on database. 4 Information about MYSQL software MySQL is an open-source relational database management system (RDBMS) that uses Structured Query Language (SQL) to manage and manipulate data. Developed by Oracle Corporation, it is widely recognized for its speed, reliability, and ease of use, making it one of the most popular database systems globally. MySQL stores data in tables organized into schemas, allowing developers to efficiently manage structured data such as text, numbers, dates, and JSON. It supports ACID transactions (Atomicity, Consistency, Isolation, Durability), ensuring data integrity and reliability even in high-demand environments. Key Features ● Open Source: Freely available with the option for commercial licensing. ● High Performance: Optimized for fast data retrieval and processing. ● Scalability: Handles large datasets and high traffic with features like replication and clustering. ● Cross-Platform Support: Runs on Windows, Linux, macOS, and more. ● Security: Offers user authentication, SSL encryption, and secure data storage. ● Multiple Storage Engines: Includes InnoDB (ACID-compliant) and MyISAM for flexibility. EXPERIMENT NO: 1 AIM: Identify the case study and detail statement of problem. Design an Entity-Relationship (ER) / Extended Entity-Relationship (EER) Model SOFTWARE REQUIRED: - NA THEORY: E-R Diagrams in DBMS: E-R diagram is the short form of “Entity-Relationship” diagram. An e-r diagram efficiently shows the relationships between various entities stored in a database. In this article, we will discuss what are ER Diagram, ER Diagrams Symbols, Notations, Their various components like Entity, Attribute and Relationship. ●E-R diagrams are used to represent E-R model in a database, which makes them easy to be converted into relations (tables). ●E-R diagrams provide the purpose of real-world modeling of objects which makes them intently useful. ●E-R diagrams require no technical knowledge & no hardware support. ●These diagrams are very easy to understand and easy to create even by a naive user. ●It gives a standard solution of visualizing the data logically PROCEDURE: ER Diagrams Symbols, And Notations An ER Diagram (Entity-Relationship Diagram) is a visual representation of the relationships between entities in a database. The main components of an ER diagram include: 1. Entities: Objects or concepts that can have data stored about them, represented by rectangles 2. Attributes: Characteristics or properties of entities, which can be simple, composite, derived, or multivalued 3. Relationships: Connections between entities that show how they interact with each other 4. Cardinality: Defines the numerical relationships between entities, indicating how many instances of one entity relate to instances of another Draw E-R diagram for Hospital management System with entity Patient, Medical record, Hospital and doctor. CONCLUSION: EXPERIMENT NO: 2 Aim: Mapping ER/EER to Relational schema model. Software required: NA Procedure: Converting an Entity-Relationship (ER) diagram to a Relational Model is an important step in database design. The ER model represents the conceptual structure of a database, and the Relational Model is a physical representation that can be directly implemented using a Relational Database Management System (RDBMS) like Oracle or MySQL. Case 1: Binary Relationship with 1:1 cardinality with total participation of an entity Note: A person has 0 or 1 passport number and Passport is always owned by 1 person. So it is 1:1 cardinality with full participation constraint from Passport. ● First Convert each entity and relationship to tables. ● Person table corresponds to Person Entity with key as Per-Id. Similarly, Passport table corresponds to Passport Entity with key as Pass-No. ● Has Table represented relationship between Person and Passport (Which person has which passport). So, it will take attribute Per-Id from Person and Pass-No from Passport. ● As we can see from Table 1, each Per-Id and Pass-No has only one entry in Has Table. ● So, we can merge all three tables into 1 with attributes shown in Table 2. Each Per-Id will be unique and not null. Table 1 Person Has Passport Per-Id Other Person Attribute Per-Id Pass-No Pass-No Other PassportAttribute PR1 - PR1 PS1 PS1 - PR2 - PR2 PS2 PS2 - PR3 - Table 2 Per-Id Other Person Attribute Pass-No Other PassportAttribute Note: So it will be the key. Pass-No can’t be key because for some person, it can be NULL. Case 2: Binary Relationship with 1:1 cardinality and partial participation of both entities ● A male marries 0 or 1 female and vice versa as well. So it is 1:1 cardinality with partial participation constraint from both. ● First Convert each entity and relationship to tables. ● Male table corresponds to Male Entity with key as M-Id. Similarly Female table corresponds to Female Entity with key as F-Id. ● Marry Table represents relationship between Male and Female (Which Male marries which female). So it will take attribute M-Id from Male and F-Id from Female. Table 3 Male Marry Female M-Id Other Male Attribute M-Id F-Id F-Id Other FemaleAttribute M1 - M1 F2 F1 - M2 - M2 F1 F2 - M3 - F3 - ● As we can see from Table 3, some males and some females do not marry. ● If we merge 3 tables into 1, for some M-Id, F-Id will be NULL. So there is no attribute which is always not NULL. ● So we can’t merge all three tables into 1. We can convert into 2 tables. In table 4, M-Id who are married will have F-Id associated. For others, it will be NULL. ● Table 5 will have information of all females. Primary Keys have been underlined. Table 4 M-Id Other Male Attribute F-I d Table 5 F-I d Other FemaleAttribute Note: Binary relationship with 1:1 cardinality will have 2 table if partial participation of both entities in the relationship. If atleast 1 entity has total participation, number of tables required will be 1. Case 3: Binary Relationship with n: 1 cardinality ● In this scenario, every student can enroll only in one elective course but for an elective course there can be more than one student. ● First Convert each entity and relationship to tables. Student table corresponds to Student Entity with key as S-Id. ● Similarly Elective_Course table corresponds to Elective_Course Entity with key as E-Id. ● Enrolls Table represents relationship between Student and Elective_Course (Which student enrolls in which course). So it will take attribute S-Id from Student and E-Id from Elective_Course. Table 6 Student Enrolls Elective_Course S-I d Other Student Attribute S-I d E-I d E-I d Other Elective CourseAttribute S1 - S1 E1 E1 - S2 - S2 E2 E2 - S3 - S3 E1 E3 - S4 - S4 E1 ● As we can see from Table 6, S-Id is not repeating in Enrolls Table. So it can be considered as a key of Enrolls table. ● Both Student and Enrolls Table’s key is same. We can merge it as a single table. Table 7 S-I d Other Student Attribute E-I d Table 8 E-I d Other Elective CourseAttribute Note: The resultant tables are shown in Table 7 and Table 8. Primary Keys have been underlined. Case 4: Binary Relationship with m: n cardinality ● In this scenario, every student can enroll in more than 1 compulsory course and for a compulsory course there can be more than 1 student. ● First Convert each entity and relationship to tables. Student table corresponds to Student Entity with key as S-Id. ● Similarly Compulsory_Courses table corresponds to Compulsory Courses Entity with key as C-Id. ● Enrolls Table represents relationship between Student and Compulsory_Courses (Which student enrolls in which course). So it will take attribute S-Id from Student and C-Id from Compulsory_Courses. ● As we can see from Table 9, S-Id and C-Id both are repeating in Enrolls Table. ● But its combination is unique; so it can be considered as a key of Enrolls table. Note: All tables’ keys are different, these can’t be merged. Primary Keys of all tables have been underlined. Table 9 Student Enrolls Compulsory_Courses S-I d Other Student Attribute S-I d C-I d C-Id Other Compulsory CourseAttribute S1 - S1 C1 C1 - S2 - S1 C2 C2 - S3 - S3 C1 C3 - S4 - S4 C3 C4 - S4 C2 S3 C3 Conclusion: EXPERIMENT NO: 3 Aim: Create a database using Data Definition Language (DDL) and apply integrity constraints for the specified System Software required: MYSQL Procedure: Step 1: Define the Database Structure Using DDL Data Definition Language (DDL) is used to define the structure of a database. Here are some common DDL statements: 1. CREATE TABLE: This statement creates a new table in the database. For example: CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, FirstName VARCHAR(50) NOT NULL, LastName VARCHAR(50) NOT NULL, HireDate DATE, Salary DECIMAL(10, 2) CHECK (Salary > 0) ); In this example, the Employees table is created with various columns, including a primary key and a check constraint on the salary. 2. ALTER TABLE: This statement modifies an existing table. For example, to add a new column: ALTER TABLE Employees add Email VARCHAR(100) UNIQUE; 3. DROP TABLE: This statement deletes a table from the database: DROP TABLE Employees; Step 2: Apply Integrity Constraints Integrity constraints are rules that ensure the accuracy and consistency of data within the database. Here are some common types of integrity constraints: 1. Primary Key Constraint: Ensures that each row in a table is unique. For example, EmployeeID in the Employees table is defined as a primary key. 2. Foreign Key Constraint: Ensures that a value in one table corresponds to a valid value in another table. For example: CREATE TABLE Departments ( DepartmentID INT PRIMARY KEY, DepartmentName VARCHAR(50) NOT NULL ); CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, FirstName VARCHAR(50) NOT NULL, LastName VARCHAR(50) NOT NULL, DepartmentID INT, FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID) ); 3. Unique Constraint: Ensures that all values in a column are unique. For example, the Email column in the Employees table can be defined as unique. 4. Check Constraint: Ensures that all values in a column satisfy a specific condition. For example, the Salary column can have a check constraint to ensure it is greater than zero. 5. Not Null Constraint: Ensures that a column cannot have a NULL value. For example, FirstName and LastName in the Employees table are defined as NOT NULL. Conclusion: EXPERIMENT NO: 4 Aim: Apply DML Commands for the specified system Software required: MySQL Procedure: DML stands for Data Manipulation Language. The purpose of DML is to select, insert, update, and delete data in a database. The DML commands in SQL modify or change the data present in the database. These commands are not auto-committed. This means they can’t permanently save all the changes in the database. However, they can roll back using the DML commands themselves. Following are the four main commands in DML: 1. SELECT 2. INSERT 3. UPDATE 4. DELETE Types of DML Commands in SQL with Syntax and Examples 1. INSERT Command It is a command to insert data into the table’s columns. The user must check the table to see whether it has any integrity constraints, such as PRIMARY KEY, UNIQUE, NOT NULL, etc., and enter records accordingly. Things to keep in mind while inserting data into the table using the INSERT command: Enclose the string within a single quote, ‘ ‘. Write the date as YYYY/MM/DD and enclose it within a single quote. Mention the data type along with the column name. Follow all INTEGRITY constraints. They are the rules for data being stored in the table. Syntax- INSERT INTO table_name (column_1 data type, column_2 data type,...,column_N data type) VALUES (value 1, value 2, value 3,..., value N); Example 1 – Consider an empty table called “Employee” that will contain details of all employees. The structure of the Employee table is as follows: | Emp_ID | Emp_Name | Emp_Age | Emp_City | Salary | Let us add a record of an employee to this table using the DML command INSERT. INSERT INTO Employee (Emp_ID int, ‘Emp_Name’ varchar(20), Emp_Age int, ‘Emp_City’ varchar(20), Salary int) VALUES (1, ‘Satish’, 25, ‘Pune’, 20000); INSERT INTO Employee (Emp_ID int, ‘Emp_Name’ varchar(20), Emp_Age int, ‘Emp_City’ varchar(20), Salary int) VALUES (2, ‘Ram’, 26, ‘Pune’, 21000); Similarly, you can add any number of records. To display the record, use the code – SELECT * FROM Employee; Output – Emp_ID Emp_Name Emp_Age Emp_City Salary 1 Satish 25 Pune 20000 2 Ram 26 Pune 21000 You can also simply insert values into the table. Example 2- You can also insert values into the table using another INSERT command format. No columns need to be specified if you want to insert a record that includes data from every column in the table. The values can be directly inserted with the INSERT command, which by default takes into account all columns. INSERT INTO Employee VALUES (3, ‘Chirag’, 27, ‘Jaipur’, 25000); To display the result, use the code – SELECT * FROM Employee; Output – Emp_ID Emp_Name Emp_Age Emp_City Salary 1 1 Satish 25 Pune 20000 2 2 Ram 26 Pune 21000 3 3 Chirag 27 Jaipur 25000 Example 3 – While inserting the record into the table, you may not have data for all the columns. In this case, a column that does not contain information will insert a NULL value. INSERT INTO Employee (Emp_ID int, ‘Emp_Name’ varchar(20), Emp_Age int, Salary int) VALUES (4, ‘Pankaj’, 24, 15000); Use the code below to display the result – SELECT * FROM Employee; Output – Emp_ID Emp_Name Emp_Age Emp_City Salary 1 1 Satish 25 Pune 20000 2 2 Ram 26 Pune 21000 3 3 Chirag 27 Jaipur 25000 4 4 Pankaj 24 NULL 15000 Here, for the column in which no data value was provided in the INSERT command, it inserts a NULL value by default. 2. SELECT Command It is used to select and retrieve data from the database table. Note that it does not manipulate data. The SELECT command is also known as data query language because it is used to query information from a database table. In the SELECT statement, the table name and column names are specified. It returns data in the form of a result table. These result tables are called “result sets”. Various ‘clauses’ that go with the SELECT command are WHERE, GROUP BY, HAVING, ORDER BY, AS, and DISTINCT. These clauses help filter the results stated in the SELECT clauses. Let’s discuss each of these clauses one by one. WHERE Clause: It specifies which row to retrieve from the database. GROUP BY Clause: It is used to arrange data into groups so that aggregate functions can be applied. HAVING Clause: It selects among groups defined by the Group By clause by specifying conditions. ORDER BY Clause: It specifies the order in which to return the rows. AS Clause: It is used to give a column or table with a temporary name. DISTINCT Clause: Its use is to remove duplicates from the result set of a SELECT statement (SELECT DISTINCT). Syntax – SELECT column_name1, column_name2,...FROM table_name; Example 1- To see all the records in the table Employee, there is no need to specify every column name in the statement. You can simply use * asterisk with the SELECT command. This * asterisk mark in SQL recognizes all the columns and a complete table will appear. SELECT * FROM Employee; Example 2 – To view only the employees’ IDs and names, you select only Emp_ID and Emp_Name columns in the SELECT command. SELECT Emp_ID, Emp_Name FROM Employee; Output – Emp_ID Emp_Name 1 Satish 2 Ram 3 Chirag 4 Pankaj Example 3 – To retrieve specific records from the table Employee, for instance, you want to see the information of employees who work in Pune. SELECT * FROM Employee WHERE Emp_City IN (‘Pune’); Output – Emp_ID Emp_Name Emp_Age Emp_City Salary 1 1 Satish 25 Pune 20000 2 2 Ram 26 Pune 21000 To learn more about SQL and perfect your skills as a SQL developer or business management professional, consider taking a SQL course. 3. UPDATE Command This DML command in SQL modifies the record present in the existing table. It updates the records by using a WHERE clause that specifies the condition with an UPDATE statement. You need to mention the condition, otherwise, all the rows will be affected. Syntax – UPDATE table_name SET column 1 = value 1, column 2 = value 2,..., column N = value N WHERE CONDITION; Example – UPDATE Employee SET Address = ‘Chennai’ WHERE Emp_ID = 2; Output – Emp_ID Emp_Name Emp_Age Emp_City Salary 1 1 Satish 25 Pune 20000 2 2 Ram 26 Chennai 21000 3 3 Chirag 27 Jaipur 25000 4 4 Pankaj 24 NULL 15000 It will update the employee’s address from Pune to Chennai, where the employee ID is 2. 4. DELETE Command It is used to delete some or all of the records from the existing table. It should contain the WHERE clause to give the condition. It is necessary to mention the WHERE condition to delete the selected rows; otherwise, it will delete all the data. Syntax – DELETE FROM table_name WHERE condition; Example – DELETE FROM Employee WHERE Address = ‘Pune’;