Dbms
Dbms
LABORATORY RECORD
2023-2024
NAME : …………………………………….
REG.NO : ………………………………….…
BRANCH : …………………………………….
SUBJECT CODE : …………………………………….
SUBJECT TITLE :……………………………………..
BONAFIDE CERTIFICATE
Certified that this is the bonafide record of Practical done in AD3381- DATABASE DESIGN
AIM:
To define the problem and requirements of a database system and identify its scope
and constraints.
INTRODUCTION :
Database development is just one part of the much wider field of software engineering,
the process of developing and maintaining software. A core aspect of software engineering is the
subdivision of the development process into a series of phases, or steps, each of which focuses on
one aspect of the development. The collection of these steps is sometimes referred to as a
development life cycle. The software product moves through this life cycle (sometimes repeatedly
as it is refined or redeveloped) until it is finally retired from use. Ideally, each phase in the life
cycle can be checked for correctness before moving on to the next phase.
REQUIREMENT ANALYSIS:
Data analysis begins with the statement of data requirements and then produces a
conceptual data model. The aim of analysis is to obtain a detailed description of the data that will
suit user requirements so that both high and low level properties of data and their use are dealt
with. These include properties such as the possible range of values that can be permitted for
attributes (e.g., in the school database example, the student course code, course title and credit
points).
The conceptual data model provides a shared, formal representation of what is being
communicated between clients and developers during database development – it is focused on the
data in a database, irrespective of the eventual use of that data in user processes or implementation
of the data in specific computer environments. Therefore, a conceptual data model is concerned
with the meaning and structure of data, but not with the details affecting how they are
implemented.
The conceptual data model then is a formal representation of what data a database should
contain and the constraints the data must satisfy. This should be expressed in terms that are
independent of how the model may be implemented. As a result, analysis focuses on the questions,
“What is required?” not “How is it achieved?”.
Information is gathered for each major user view (that is, job role or enterprise application area),
including:
• a description of the data used or generated;
This information is then analyzed to identify the requirements (or features) to be included in the
new database system. These requirements are described in documents collectively referred to as
requirements specifications for the new database system. The amount of data gathered depends
on
i) nature of the problem and
Identifying the required functionality for a database system is a critical activity, as systems with
inadequate or incomplete functionality will annoy the users, which may lead to rejection or
underutilization of the system. However, excessive functionality can also be problematic, as it
can overcomplicate a system, making it difficult to implement, maintain, use, or learn.
The designer has both formal and informal sources of information. The process of
defining problems might initially appear to be unstructured. Company end users are often unable
to describe precisely the larger scope of company operations or to identify the real problems
encountered during company operations.
The designer must recognize the existence of two sets of limits: scope and boundaries.
The system’s scope defines the extent of the design according to operational requirements. Will
the database design encompass the entire organization, one or more departments within the
organization, or one or more functions of a single department? Knowing the scope helps in
defining the required data structures, the type and number of entities, the physical size of the
database, and so on. Boundaries are also imposed by existing hardware and software.
RESULT:
Thus the study on problem definition, requirement analysis, scope and constraints of
database development life cycle is successfully performed.
EX.NO : 2(a) DATABASE DESIGN USING CONCEPTUAL MODELING (ER-EER) –
TOP-DOWN APPROACH MAPPING CONCEPTUAL TO RELATIONAL
DATE: DATABASE AND VALIDATE USING NORMALIZATION FOR COLLEGE
MANAGEMENT SYSTEM
AIM:
CONCEPTUAL DESIGN:
The process of constructing a model of the data used in an enterprise, independent of all
physical considerations.
COMMANDS:
• CREATE
• INSERT
• DELETE
ER DIAGRAM :
PROGRAM:
CREATE TABLE
INSERT 0 3
CREATE TABLE
INSERT 0 3
CREATE TABLE
INSERT 0 3
RESULT:
Thus the database design using conceptual modeling (ER-EER) and map it to
relational database using normalization for college management system is performed
successfully.
EX.NO : 2(b) DATABASE DESIGN USING CONCEPTUAL MODELING (ER-EER) –
TOP-DOWN APPROACH MAPPING CONCEPTUAL TO RELATIONAL
DATE: DATABASE AND VALIDATE USING NORMALIZATION FOR
HOSPITAL MANAGEMENT SYSTEM
AIM:
CONCEPTUAL DESIGN:
The process of constructing a model of the data used in an enterprise, independent of all
physical considerations.
COMMANDS:
• CREATE
• INSERT
• DELETE
ER DIAGRAM :
PROGRAM :
-- Creating a patient table with specified columns
CREATE TABLE patient (
name VARCHAR(100),
age INT,
patient_id INT PRIMARY KEY,
diagnosis VARCHAR(100),
doctor_id INT
);
-- Creating a doctor table with specified columns
CREATE TABLE doctor (
name VARCHAR(100),
age INT,
doctor_id INT PRIMARY KEY,
specialization VARCHAR(100),
salary INT
);
-- Adding the correct references to the doctor_id column in the patient table
ALTER TABLE patient
ADD FOREIGN KEY (doctor_id) REFERENCES doctor(doctor_id);
CREATE TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
RESULT :
Thus the database design using conceptual modeling (ER-EER) and map it to
relational database using normalization for hospital management system is performed
successfully.
EX.NO : 2(c) DATABASE DESIGN USING CONCEPTUAL MODELING (ER-EER) –
TOP-DOWN APPROACH MAPPING CONCEPTUAL TO RELATIONAL
DATE: DATABASE AND VALIDATE USING NORMALIZATION FOR HOTEL
MANAGEMENT SYSTEM
AIM:
CONCEPTUAL DESIGN:
The process of constructing a model of the data used in an enterprise, independent of all
physical considerations.
COMMANDS:
• CREATE
• INSERT
• DELETE
ER DIAGRAM :
PROGRAM :
-- Creating a room table with specified columns
CREATE TABLE room (
room_no INT PRIMARY KEY,
room_type VARCHAR(100),
price INT
);
CREATE TABLE
INSERT 0 3
CREATE TABLE
INSERT 0 3
CREATE TABLE
INSERT 0 3
RESULT :
Thus the database design using conceptual modeling (ER-EER) and map it to
relational database using normalization for hotel management system is performed successfully.
EX.NO : 2(d) DATABASE DESIGN USING CONCEPTUAL MODELING (ER-EER) –
TOP-DOWN APPROACH MAPPING CONCEPTUAL TO RELATIONAL
DATE: DATABASE AND VALIDATE USING NORMALIZATION FOR BANK
MANAGEMENT SYSTEM
AIM:
CONCEPTUAL DESIGN:
The process of constructing a model of the data used in an enterprise, independent of all
physical considerations.
COMMANDS:
• CREATE
• INSERT
• DELETE
ER DIAGRAM :
PROGRAM :
CREATE TABLE
INSERT 0 3
CREATE TABLE
INSERT 0 3
CREATE TABLE
INSERT 0 3
RESULT :
Thus the database design using conceptual modeling (ER-EER) and map it to
relational database using normalization for bank management system is performed successfully.
EX.NO : 3
IMPLEMENT THE DATABASE USING SQL DATA DEFINITION WITH
DATE: CONSTRAINTS, VIEWS
AIM :
To implement the database using SQL data definition language and create constraints
and views.
COMMAND :
• Create
• Alter
• Drop
• Truncate
PROCEDURE :
1. Create a new database for the student system using CREATE DATABASE statement.
2. Use CREATE TABLE to establish the "Students" table with columns: StudentID (Primary
Key, Identity), FirstName (Not Null), LastName (Not Null), Email (Unique), and DepartmentID
(Foreign Key).
4. Utilize CREATE VIEW to make querying data easier, like creating a view showing students
enrolled in a specific department.
5. Test the created views and tables by running queries to ensure they function as expected.
6. Modify existing table structures if needed using the ALTER TABLE statement.
7. If necessary, remove tables from the student database permanently using the DROP TABLE
statement. Exercise caution, as this action deletes the table and its data.
8. Retrieve and display all records from the "student" table after the deletion. 1. Create a new
database for the student system using CREATE DATABASE statement.
2. Use CREATE TABLE to establish the "Students" table with columns: StudentID (Primary
Key, Identity), FirstName (Not Null), LastName (Not Null), Email (Unique), and DepartmentID
(Foreign Key).
4. Utilize CREATE VIEW to make querying data easier, like creating a view showing students
enrolled in a specific department.
5. Test the created views and tables by running queries to ensure they function as expected.
6. Modify existing table structures if needed using the ALTER TABLE statement.
7. If necessary, remove tables from the student database permanently using the DROP TABLE
statement. Exercise caution, as this action deletes the table and its data.
8. Retrieve and display all records from the "student" table after the deletion.
PROGRAM :
---View honor_roll
Select * from honor_roll
CREATE TABLE
CREATE TABLE
INSERT 0 3
CREATE VIEW
UPDATE 1
DELETE 1
RESULT :
Thus the implementation of the database using SQL data definition with constraints,
views is performed successfully.
EX.NO : 4
QUERY THE DATABASE USING SQL MANIPULATION
DATE:
AIM :
To query the database using SQL data manipulation language and perform various
operations on the data.
PROCEDURE :
1. Create a table named "Student" with columns: StudentID (primary key), FirstName,
LastName, Age, and GPA.
2. Insert multiple student records with details, including StudentID, FirstName, LastName, Age,
and GPA, into the "Student" table.
3. Retrieve and display all student records from the "Student" table using the SELECT
command.
4. Identify a specific student by StudentID using the WHERE clause with the UPDATE
command.
- Increment the student's Age by 1 and multiply their GPA by 1.1.
5. Identify a specific student by StudentID using the WHERE clause with the DELETE
command.
- Remove the corresponding record from the "Student" table.
6. Retrieve and display students with a GPA greater than 3.5 or whose StudentID is in a
specified list using the SELECT command.
- Optionally, use an alias for the GPA column with AS.
- Employ the WHERE clause with conditions for GPA and StudentID.
7. Retrieve and display students whose StudentID is not in a specified list using the SELECT
command.
- Filter records based on an age range (e.g., BETWEEN 20 AND 22) with the WHERE
clause.
- Order the results by GPA in descending order using the ORDER BY command.
PROGRAM :
-- Delete a student
DELETE FROM Student
WHERE StudentID = 3;
-- Select students not in a specific list and age between 20 and 22, order by GPA
SELECT StudentID, FirstName, LastName, GPA AS GradePointAverage
FROM Student
WHERE StudentID NOT IN (1)
AND Age BETWEEN 20 AND 22
ORDER BY GPA DESC;
OUTPUT :
CREATE TABLE
INSERT 0 5
UPDATE 1
DELETE 1
RESULT :
Thus the query on the database using SQL manipulation is performed
successfully.
EX.NO : 5(a)
QUERYING/MANAGING THE DATABASE USING SQL PROGRAMMING -
STORED PROCEDURES/FUNCTIONS - CONSTRAINTS AND SECURITY
DATE: USING TRIGGERS
AIM :
To manage the database using SQL programming and create stored procedures,
functions, triggers, and security features.
COMMANDS :
• CREATE PROCEDURE
• CREATE FUNCTION
• ALTER PROCEDURE
• ALTER FUNCTION
• DROP PROCEDURE
• DROP FUNCTION
• EXECUTE
• CALL
• DECLARE
• SET
• SELECT
• INSERT
• UPDATE
• DELETE
• BEGIN
• END
• IF
• ELSE
• WHILE
• RETURN
PROCEDURE :
1. Defines the structure of the "Employees" table with columns for EmployeeID, FirstName,
LastName, Department, and Salary, specifying EmployeeID as the primary key.
2. Inserts sample data into the "Employees" table with Indian names, employee IDs,
departments, and salaries.
5. Defines a stored procedure named AddEmployee to add a new employee record with
provided details using the INSERT INTO command.
6. Retrieves all records from the "Employees" table using the SELECT command.
7. Filters and retrieves employees who work in the IT department using the SELECT command
with a WHERE clause.
8. Filters and retrieves employees with a salary greater than 60000.00 using the SELECT
command with a WHERE clause.
PROGRAM :
FirstName VARCHAR(50),
LastName VARCHAR(50),
Department VARCHAR(50),
Salary DECIMAL(10,2)
);
VALUES
employee_id_param INT
) RETURNS TABLE (
EmployeeID INT,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Department VARCHAR(50),
Salary DECIMAL(10,2)
) AS $$
BEGIN
RETURN QUERY
SELECT *
FROM Employees
$$ LANGUAGE plpgsql;
) RETURNS INT AS $$
BEGIN
UPDATE Employees
END;
$$ LANGUAGE plpgsql;
first_name_param VARCHAR(50),
last_name_param VARCHAR(50),
department_param VARCHAR(50),
salary_param DECIMAL(10,2)
) RETURNS VOID AS $$
BEGIN
$$ LANGUAGE plpgsql;
CREATE TABLE
INSERT 0 3
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
RESULT :
Thus the querying/managing on the database using SQL programming - stored
procedures/functions is performed successfully.
EX.NO : 5(b)
QUERYING/MANAGING THE DATABASE USING SQL PROGRAMMING -
STORED PROCEDURES/FUNCTIONS - CONSTRAINTS AND SECURITY
DATE: USING TRIGGERS
AIM :
To manage the database using SQL programming and create stored procedures,
functions, triggers, and security features.
COMMANDS :
• CREATE PROCEDURE
• CREATE FUNCTION
• ALTER PROCEDURE
• ALTER FUNCTION
• DROP PROCEDURE
• DROP FUNCTION
• EXECUTE
• CALL
• DECLARE
• SET
• SELECT
• INSERT
• UPDATE
• DELETE
• BEGIN
• END
• IF
• ELSE
• WHILE
• RETURN
PROCEDURE :
1. The script initiates by establishing a table named "Employees" with fundamental attributes
such as EmployeeID, FirstName, LastName, Salary, and HireDate.
4. To illustrate the functionality, the script populates the Employees table with sample data for
two employees, providing specific details such as EmployeeID, names, salary, and hire dates.
5. Employing the SELECT statement, the script retrieves and showcases all available records
within the Employees table, presenting comprehensive information about each employee.
6. In addition, a SELECT statement filters and retrieves records from the Employees table
where the salary surpasses $35,000, offering a targeted view of higher-salaried employees.
7. A subsequent UPDATE statement dynamically adjusts the salary of the employee with
EmployeeID 1 to $38,000, showcasing the script's ability to modify existing data.
8. Lastly, a DELETE statement is utilized to remove the employee with EmployeeID 2 from the
Employees table, highlighting the script's capability to manage and eliminate specific records.
PROGRAM :
FirstName VARCHAR(50),
LastName VARCHAR(50),
HireDate DATE
);
EmployeeID INT,
ActionMessage VARCHAR(255),
ActionTime TIMESTAMP
);
RETURNS TRIGGER AS $$
BEGIN
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
RETURNS TRIGGER AS $$
BEGIN
RETURN NULL;
END;
$$ LANGUAGE plpgsql;
VALUES
-- Deleting an employee
CREATE TABLE
CREATE TABLE
CREATE FUNCTION
CREATE TRIGGER
CREATE FUNCTION
CREATE TRIGGER
INSERT 0 2
UPDATE 1
DELETE 1
RESULT :
Thus querying/managing on the database using programming - stored
procedures/functions - constraints and security using triggers
EX.NO : 6 DATABASE DESIGN USING NORMALIZATION – BOTTOM-UP
DATE: APPROACH
AIM :
To design a database using normalization and decompose the relations into smaller ones
based on functional dependencies.
COMMANDS :
PROCEDURE :
1. Normalization Purpose:
- Reduce complex user views to small, stable subgroups for logical data modeling.
2. Normalization Levels:
- Use CREATE TABLE to define tables with atomic values in attribute domains.
- Establish full functional dependencies by designing tables with proper primary keys.
- Regularly check for anomalies and dependencies that violate normal forms.
- Employ proper indexing for performance improvement, considering specific querying needs.
This breakdown emphasizes the conceptual steps of normalization and the practical use of SQL
commands for creating and modifying tables to achieve normalization.
PROGRAM :
CREATE TABLE
CREATE TABLE
CREATE TABLE
INSERT 0 1
INSERT 0 1
CREATE TABLE
CREATE TABLE
INSERT 0 1
INSERT 0 1
CREATE TABLE
INSERT 0 1
CREATE TABLE
CREATE TABLE
INSERT 0 1
INSERT 0 1
RESULT :
Thus the database design using normalization – bottom-up approach is performed
successfully.
EX.NO : 7
DEVELOPING A DATABASE APPLICATIONS USING VISUALSTUDIO
DATE:
AIM :
PROCEDURE :
2. Create Database: Establish a connection to the SQLite database and create a cursor object.
3. Define Table: Create a table named "employees" with specified fields (id, name, age, doj,
email, gender, contact, address).
5. Fetch and Display Data: Retrieve all data from the table and display it.
7. Create Root Window: Create a root window for the GUI application.
8. Configure Window: Set title, geometry, background color, and state (zoomed) of the root
window.
10. Finalize Database Creation: Commit changes, close the database connection, and finalize
the database creation process.
PROGRAM :
import sqlite3
# Database setup
db = sqlite3.connect("employee_database.db")
cursor = db.cursor()
cursor.execute('''
name TEXT,
age INTEGER,
doj TEXT,
email TEXT,
gender TEXT,
contact TEXT,
address TEXT
''')
db.commit()
# Functions
def add_employee():
# ... [same as before]
def update_employee():
def delete_employee():
def clear_all_entries():
def get_data(event):
def display_all_records():
# GUI
root = Tk()
root.geometry("1080x720+0+0")
root.config(bg="#2c3e50")
entries_frame.pack(side=TOP, fill=X)
# Buttons
# Treeview
tv = ttk.Treeview(root)
tv.heading(str(idx), text=col)
tv['show'] = 'headings'
tv.bind("<ButtonRelease-1>", get_data)
tv.pack(fill=X)
display_all_records()
root.mainloop()
OUTPUT :
RESULT:
Thus the application to develop Employee Management System using VisualStudio
is successfully implemented.
EX.NO : 8
DATABASE DESIGN USING EER-TO-ODB MAPPING / UML CLASS
DATE: DIAGRAMS
AIM :
To design a database using EER-to-ODB mapping and create UML class diagrams for
the object-oriented database model.
ALGORITHM :
1. Develop EER or UML diagrams representing system entities, attributes, and relationships.
2. Extract entities and attributes for tables, considering each entity as a table and attributes as
columns.
3. Translate relationships into foreign keys in corresponding tables, considering cardinalities and
participation constraints.
6. Assign appropriate data types to attributes based on requirements and the DBMS.
8. Establish primary keys, foreign keys, unique constraints, and other integrity constraints.
9. Create a SQL script to implement the database schema, relationships, and constraints.
10. Execute the SQL script to create the database, test and optimize the schema for performance
and functionality, and document the structure.
DETAILS OF THE CLASSES:
Usertype
Username
PasswordOperations:
Login()
Register()
Logout()
2.User Attributes:
Name
Id Operations: Verify()
CheckAccount()
get_book_info()
3. staff Attributes:
Dept
4. Student Attributes:
Class
5. AccountAttributes:
6. Book Attributes:
Title
Author
ISBN
publication Operations: Show_duedt()
Reservation_status()
Feedback()
Book_request()
Renew_info()
7. librarianAttributes:
Name
Id
Password
SearchString Operations: Verify_librarian()
Search()
8. Library database
Attributes:
List_of_books Operations:
Add()
Delete()
Update()
Display()
Search()
UML DIAGRAM :
RESULT :
Thus the implementation on database design using eer-to-odb mapping / uml class
diagrams is performed successfully.
EX.NO : 9(a)
OBJECT FEATURES OF TABLES USING UDTS
DATE:
AIM :
COMMANDS :
• CREATE
• SELECT
• TYPE
• INSERT
PROCEDURE :
1. Specify the fields and data types for the UDT and create it.
3. Insert records into the table using the UDT for structured data.
4. Retrieve and display records from the table using SQL queries.
8. Retrieve and display records from the sub-type table using SQL queries.
street VARCHAR(100),
city VARCHAR(50),
country VARCHAR(50)
);
emp_name VARCHAR(100),
emp_address address_type
);
VALUES
street_address VARCHAR(255),
city VARCHAR(100),
province VARCHAR(50),
postal_code VARCHAR(10)
);
emp_name VARCHAR(100),
emp_address canadian_address
);
VALUES
CREATE TYPE
CREATE TABLE
INSERT 0 2
CREATE TYPE
CREATE TABLE
INSERT 0 1
RESULT :
AIM :
COMMANDS :
• CREATE
• SELECT
• TYPE
• INSERT
PROCEDURE :
2. Create a table that utilizes the UDT for one or more of its columns.
3. Insert records into the table using the UDT for structured data.
4. Retrieve and display records from the table using SQL queries.
5. Update records within the table that involve the UDT columns.
street VARCHAR(100),
city VARCHAR(50),
country VARCHAR(50)
);
emp_name VARCHAR(100),
emp_address address_type
VALUES
UPDATE employees
CREATE TYPE
CREATE TABLE
INSERT 0
UPDATE 1
DELETE 1
RESULT :
AIM :
COMMANDS :
• CREATE
• SELECT
• TYPE
• INSERT
PROCEDURE :
CREATE TABLE
INSERT 0 2
CREATE TABLE
INSERT 0 2
UPDATE 1
DELETE 1
RESULT :
AIM :
COMMANDS :
• CREATE
• SELECT
• TYPE
• INSERT
PROCEDURE :
2. Specify the return type of the function and the language used (e.g., plpgsql for PostgreSQL).
4. Optionally declare local variables within the function for temporary storage.
5. Use control structures like loops or conditionals to implement the desired functionality.
7. Call the function in SQL queries to utilize its functionality and display the output.
PROGRAM :
RETURNS FLOAT AS $$
BEGIN
END;
$$ LANGUAGE plpgsql;
RETURNS INT AS $$
DECLARE
i INT;
BEGIN
max_val := arr[i];
END IF;
END LOOP;
RETURN max_val;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION
CREATE FUNCTION
RESULT :
AIM :
To query the object-relational database using object query language and access the data
stored in the objects.
COMMANDS:
• CREATE TABLE
• INSERT INTO
• SELECT COUNT(*)
• SELECT DISTINCT
• SELECT ... JOIN ... ON
• SELECT *
• DELETE FROM
• UPDATE
• DROP TABLE
PROCEDURE:
1. Define tables with their respective columns, specifying data types and constraints.
5. Perform JOIN operations to fetch common values between two tables based on related
attributes.
6. Utilize the OR operator to fetch rows meeting either of two conditions.
7. Use the AND operator to fetch rows meeting all specified conditions.
8. Apply the LIKE operator with wildcard (%) to fetch rows based on pattern matching.
9. Count the number of rows in a specific table using the COUNT function.
10. Delete specific rows from a table based on certain conditions using the DELETE statement.
11. Update existing rows in a table based on specified conditions using the UPDATE statement.
12. Delete an entire table and its associated data using the DROP TABLE statement.
PROGRAM :
EmployeeId INT,
Name VARCHAR(15),
Skills VARCHAR(30),
Gender VARCHAR(8),
Age INT
);
EmployeeID INT,
EmployeeName VARCHAR(20),
Department VARCHAR(15),
Gender VARCHAR(7),
Age INT
);
EmployeeId INT,
Name VARCHAR(20),
Gender VARCHAR(20),
Age INT,
Extrainfo VARCHAR(50)
);
FROM staffemployee e
-- Updating the Age of employees in staffemployee where the Skills include 'Java'
CREATE TABLE
INSERT 0 1
CREATE TABLE
INSERT 0 1
CREATE TABLE
INSERT 0 1
DELETE 1
UPDATE 1
DROP TABLE
RESULT :