Amulay
Amulay
PRACTICAL FILE
Submitted for partial fulfillment for the award of the Degree
of
1
INDEX
2
INFORMATION SYSTEM MANAGEMENT
LAB FILE
PAPER CODE: BBA-307
3
3. Data Control Language (DCL): DCL commands manage access
permissions and define privileges in a database. For example:
o GRANT: Grants specific privileges to users.
o REVOKE: Removes previously granted privileges.
4. Transaction Control Language (TCL): SQL also provides commands to
manage transactions (a series of related SQL operations). This is crucial
for maintaining data integrity and preventing errors during multi-step
operations. Common TCL commands include:
o COMMIT: Saves all changes made in a transaction to the
database.
o ROLLBACK: Undoes all changes made in the current transaction
if something goes wrong.
5. Relational Databases: SQL is specifically used for relational databases,
which store data in tables (rows and columns). These tables can be linked
or related to each other based on common data values, hence the term
"relational." SQL provides powerful mechanisms, such as JOINs, to
combine data from multiple related tables.
6. SQL Queries: SQL allows for complex querying of data. A query
typically starts with the SELECT statement, and users can add clauses
such as:
o WHERE: Filters rows based on specified conditions.
o GROUP BY: Groups rows that have the same values in specified
columns, often used with aggregate functions like COUNT, SUM,
and AVG.
o ORDER BY: Sorts the result set based on one or more columns.
7. Functions and Expressions: SQL includes built-in functions to perform
calculations, manipulate strings, work with dates, and aggregate data.
Examples include:
o Aggregate functions: COUNT(), SUM(), MAX(), MIN(), AVG().
o String functions: CONCAT(), UPPER(), LOWER(),
SUBSTRING().
o Date functions: NOW(), DATEDIFF(), DATEADD().
8. Normalization and Integrity: SQL plays a key role in enforcing
normalization, which organizes data to reduce redundancy and improve
4
data integrity. Constraints such as primary keys, foreign keys, unique
keys, and checks ensure the accuracy and consistency of data.
SQL Standardization:
SQL has been standardized by various organizations, including the American
National Standards Institute (ANSI) and the International Organization for
Standardization (ISO). These standards ensure that SQL is consistent across
different platforms, though there are often vendor-specific extensions in
databases like Oracle or Microsoft SQL Server.
Advantages of SQL:
Simplicity: SQL uses English-like commands, making it easy to learn
and use.
Powerful Querying: SQL can handle both simple and highly complex
queries to retrieve specific data from large databases.
Cross-Platform: SQL is supported by virtually all relational database
systems, providing flexibility in switching between databases.
Data Integrity: SQL ensures data accuracy through constraints and
transaction controls.
Scalability: SQL can efficiently manage both small and large amounts of
data.
Conclusion:
SQL remains the backbone of database management, enabling organizations to
store, retrieve, and analyze their data efficiently. Its wide adoption across
industries makes it an essential skill for developers, data analysts, and database
administrators.
5
Q2. Types of data type.
= In SQL, data types define the kind of values that can be stored in a column.
Each column in a database table must be assigned a specific data type, which
dictates how SQL will interpret and store that data. SQL supports a wide variety
of data types, typically categorized into several groups: numeric, string
(character), date/time, and others like binary and spatial types.
6
DECIMAL / NUMERIC:
o Stores exact numeric values with a fixed decimal point.
o Ideal for storing precise financial data (e.g., currency values).
o Defined as DECIMAL(p, s) where p is the precision (total number
of digits) and s is the scale (digits after the decimal point).
FLOAT:
o Stores approximate numeric values with floating decimal points.
o Suitable for scientific calculations where absolute precision isn't
critical.
o FLOAT is typically less precise than DECIMAL, as it
approximates values.
REAL / DOUBLE:
o Similar to FLOAT, but with larger precision and storage capacity.
o Used when more accuracy is needed than a FLOAT can provide.
7
o Typically used for storing names, addresses, or other variable-
length textual data.
Conclusion:
Choosing the right data type is crucial for ensuring data integrity, efficient
storage, and effective querying. Each data type in SQL is tailored for specific
kinds of data, and understanding them ensures that databases are optimized for
performance and accuracy. Whether handling numbers, strings, dates, or even
binary data, SQL offers a versatile range of types to manage a wide array of data
formats.
8
Examples:
Creating a Database:
CREATE DATABASE my_database;
This command creates a new database named my_database.
Creating a Table:
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
hire_date DATE,
salary DECIMAL(10, 2))
This command creates a new table named employees with four columns:
employee_id, first_name, last_name, hire_date, and salary. The employee_id
column is set as the primary key.
Creating an Index:
CREATE INDEX idx_last_name ON employees(last_name);
This creates an index on the last_name column of the employees table to
improve query performance when searching by last_name.
Creating a View:
CREATE VIEW employee_salaries AS
SELECT first_name, last_name, salary
FROM employees;
9
A view named employee_salaries is created, which provides a simplified
interface for querying the first_name, last_name, and salary columns from the
employees table.
2. ALTER
The ALTER command is used to modify the structure of an existing database
object. Common uses of ALTER include adding or deleting columns in a table,
changing data types, or modifying constraints.
Examples:
Adding a Column to a Table:
ALTER TABLE employees
ADD department VARCHAR(100);
This adds a new column called department to the employees table.
Modifying a Column Data Type:
ALTER TABLE employees
MODIFY salary DECIMAL(12, 2);
This modifies the data type of the salary column to allow larger decimal values
(in this case, up to 12 digits, with 2 digits after the decimal).
10
3. DROP
The DROP command is used to delete objects from the database, such as tables,
databases, indexes, or views. Be careful when using DROP because it removes
the object entirely, including its data, and this action cannot be undone.
Examples:
Dropping a Database:
DROP DATABASE my_database;
This command deletes the entire my_database and all its contents (tables, views,
etc.).
Dropping a Table:
DROP TABLE employees;
This command deletes the employees table and all the data stored in it.
Dropping an Index:
DROP INDEX idx_last_name ON employees;
This command deletes the index idx_last_name on the employees table.
Dropping a View:
DROP VIEW employee_salaries;
This command deletes the view employee_salaries.
4. TRUNCATE
The TRUNCATE command is used to remove all rows from a table, while
keeping the table structure intact. Unlike DELETE, which can remove specific
rows and logs each deletion, TRUNCATE is faster because it doesn't log
individual row deletions. However, TRUNCATE cannot be rolled back in many
systems and is a more drastic operation.
Example:
TRUNCATE TABLE employees;
This command deletes all rows from the employees table, but keeps the table
and its structure available for future use.
11
5. RENAME
The RENAME command is used to rename database objects such as tables,
views, or columns. This is often necessary when adjusting to new naming
conventions or when a more meaningful name is needed.
Examples:
Renaming a Table:
RENAME TABLE employees TO staff;
This command renames the table employees to staff.
Renaming a Column: Some database systems, like MySQL, allow
renaming a column using ALTER:
ALTER TABLE employees RENAME COLUMN first_name TO given_name;
6. COMMENT
Some database systems support a COMMENT command to add metadata
comments to database objects, helping developers and database administrators
understand the structure and purpose of the objects.
Example:
COMMENT ON COLUMN employees.salary IS 'Salary in USD';
This command adds a comment to the salary column of the employees table,
specifying that the values represent salaries in USD.
1. INSERT
The INSERT command is used to add new rows of data into a table. You can
insert data into all columns or specific columns, depending on the need.
12
Syntax:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Example:
INSERT INTO employees (employee_id, first_name, last_name, hire_date,
salary)
VALUES (101, 'John', 'Doe', '2024-01-01', 50000);
This command inserts a new row into the employees table with values for the
employee_id, first_name, last_name, hire_date, and salary columns.
INSERT INTO ... SELECT: This variation inserts rows based on data
retrieved from another table.
INSERT INTO employees_archive (employee_id, first_name, last_name,
salary)
SELECT employee_id, first_name, last_name, salary
FROM employees WHERE salary > 60000;
2. UPDATE
The UPDATE command is used to modify existing data in a table. It updates
one or more columns for one or more rows, depending on the condition
specified.
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Example:
UPDATE employees
SET salary = salary * 1.10
WHERE department = 'Sales';
13
This command updates the salary column for all employees in the Sales
department, giving them a 10% raise.
Without WHERE: If the WHERE clause is omitted, all rows in the table
will be updated. Use it cautiously!
UPDATE employees
SET salary = 50000;
This command would set the salary of every employee in the table to 50,000,
which may not be desired unless intentionally resetting all values.
3. DELETE
The DELETE command removes rows from a table based on a given condition.
Unlike TRUNCATE (a DDL command), which removes all rows, DELETE
allows you to remove specific rows.
Syntax:
DELETE FROM table_name
WHERE condition;
Example:
DELETE FROM employees
WHERE employee_id = 101;
This command deletes the row where employee_id is 101 from the employees
table.
Without WHERE: Similar to UPDATE, if the WHERE clause is
omitted, all rows in the table will be deleted. This would remove all data
from the table, but the table itself would remain.
DELETE FROM employees;
This command would delete all rows from the employees table, but the structure
of the table remains intact.
14
4. SELECT
The SELECT command is used to retrieve data from one or more tables. It
allows you to specify which columns to retrieve, filter rows based on
conditions, and even perform aggregations like counting, summing, or
averaging values.
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Example:
Simple Select:
SELECT first_name, last_name, salary
FROM employees
WHERE department = 'Sales';
This retrieves the first_name, last_name, and salary of all employees in the
Sales department.
15
Q5. Write a query to create a table called Employees with the following
columns:
EmployeeID (INT, Primary Key)
FirstName (VARCHAR)
LastName (VARCHAR)
Age (INT)
Department (VARCHAR)
Salary (INT)
= To create a table called Employees with the specified columns, the SQL query
would look like this:
16
EmployeeID: An integer that serves as the primary key, ensuring each
employee has a unique ID.
FirstName and LastName: Variable-length strings (VARCHAR) to store
the employee's first and last names, with a maximum length of 50
characters.
Age: An integer to store the age of the employee.
Department: A variable-length string to store the department name, also
up to 50 characters.
Salary: An integer representing the employee's salary.
You can adjust the VARCHAR lengths based on the expected maximum length
of the data for each field.
Q6. Write a query and insert 10 records into the Employees table
= To insert 10 records into the Employees table, you can use the INSERT INTO
statement. Below is an example SQL query that inserts ten records into the
Employees table:
17
Explanation:
The INSERT INTO Employees statement specifies the table where you
want to insert records.
The columns are specified in parentheses: (EmployeeID, FirstName,
LastName, Age, Department, Salary).
The VALUES keyword is followed by multiple sets of values, each
enclosed in parentheses and separated by commas.
This command will insert all ten records into the Employees table in one go. If
there are still issues, please ensure that the table has been created and that there
are no conflicts with existing data, especially with the EmployeeID primary key.
Q7. Write a query to select all columns from the employee table.
To select all columns from the Employees table, you can use the following SQL
query:
SELECT * FROM Employees;
18
19
Explanation:
SELECT: This keyword is used to specify which columns you want to
retrieve.
*: The asterisk (*) is a wildcard that means "all columns."
FROM Employees: This specifies the table from which you want to
retrieve the data.
Running this query will return all the records and columns in the Employees
table.
20
Explanation:
SELECT FirstName, LastName, Salary: This part specifies the
columns you want to retrieve.
FROM Employees: This indicates that you are querying data from the
Employees table.
WHERE Department = 'IT': This condition filters the results to include
only those employees who work in the IT department.
Running this query will return the first name, last name, and salary of all
employees in the IT department.
Q9. Retrieve details of employees with a salary greater than 55,000, sorted by
Salary in descending order.
21
Explanation:
SELECT *: This selects all columns from the Employees table.
FROM Employees: This specifies the table from which to retrieve the
data.
WHERE Salary > 55000: This condition filters the results to include
only employees with a salary greater than 55,000.
ORDER BY Salary DESC: This sorts the results by the Salary column
in descending order, meaning the highest salaries will appear first.
Executing this query will give you a list of employees who earn more than
55,000, along with all their details, sorted from the highest salary to the lowest.
Q10. Write a query to update the salary of the employee with EmployeeID = 1
to 55,000
22
Explanation:
UPDATE Employees: This specifies the table you want to update.
SET Salary = 55000: This sets the Salary column to 55,000 for the
specified employee.
WHERE EmployeeID = 1: This condition ensures that only the
employee with EmployeeID equal to 1 will be affected by this update.
Executing this query will change the salary of the employee with EmployeeID =
1 to 55,000.
23
Explanation:
UPDATE Employees: This specifies the table you want to update.
SET Salary = Salary * 1.10: This updates the Salary column by
multiplying the current salary by 1.10 (which represents a 10% increase).
WHERE Department = 'HR': This condition ensures that only
employees in the HR department will have their salaries updated.
Executing this query will increase the salary of all employees in the HR
department by 10%.
Q12. Write a query to add a new column HireDate (DATE) to the employees
table.
24
Explanation:
ALTER TABLE Employees: This specifies that you want to modify the
existing Employees table.
ADD HireDate DATE: This part of the command adds a new column
called HireDate with the data type DATE.
Executing this query will successfully add the HireDate column to the
Employees table.
Explanation:
DELETE FROM Employees: This specifies that you want to remove
records from the Employees table.
WHERE EmployeeID = 2: This condition ensures that only the
employee with EmployeeID equal to 2 will be deleted.
Executing this query will permanently remove the record of the employee with
EmployeeID = 2 from the Employees table.
Q14. Delete all employees from the sales department.
25
Q15. Write a query to calculate the total salary of all employees.
26
Explanation:
SELECT SUM(Salary): This part of the query calculates the sum of the
Salary column.
AS TotalSalary: This gives a name (alias) to the resulting column for
clarity in the output.
FROM Employees: This specifies the table from which to retrieve the
data.
Executing this query will return a single value representing the total salary of all
employees in the Employees table.
Explanation:
SELECT AVG(Salary): This part calculates the average of the Salary
column.
AS AverageSalary: This provides an alias for the resulting column,
making it clear in the output.
FROM Employees: This specifies the table from which to retrieve the
data.
27
WHERE Department = 'IT': This condition filters the results to include
only employees in the IT department.
Executing this query will return the average salary of all employees working in
the IT department.
Explanation:
SELECT COUNT(*): This counts the total number of rows that match
the specified condition.
AS NumberOfEmployees: This gives a name (alias) to the resulting
count for clarity in the output.
FROM Employees: This specifies the table from which to retrieve the
data.
WHERE Department = 'HR': This condition filters the results to
include only employees in the HR department.
Executing this query will return a single value representing the number of
employees in the HR department.
Q18. Write a query to find the highest and lowest salary in the employee table.
28
Q19. Write a query to group employees by Department and calculate the total
salary for each department.
Explanation:
29
SELECT Department: This specifies that you want to retrieve the
department names.
SUM(Salary): This calculates the total salary for each department.
AS TotalSalary: This gives a name (alias) to the resulting total salary
column.
FROM Employees: This specifies the table from which to retrieve the
data.
GROUP BY Department: This groups the results by the Department
column, so that the SUM(Salary) calculation is applied to each
department separately.
Executing this query will return a list of departments along with the total salary
for each department.
Q20. Write a query to group employees by Age and calculate the average salary
for each age group.
Explanation:
30
SELECT Age: This specifies that you want to retrieve the age of the
employees.
AVG(Salary): This calculates the average salary for each age group.
AS AverageSalary: This provides an alias for the resulting average salary
column.
FROM Employees: This indicates the table from which to retrieve the
data.
GROUP BY Age: This groups the results by the Age column, so that the
AVG(Salary) calculation is applied to each age group.
Executing this query will return a list of ages along with the average salary for
each age group.
Explanation:
31
SELECT Department: This retrieves the names of the departments.
COUNT(*): This counts the total number of employees in each
department.
AS NumberOfEmployees: This provides an alias for the resulting count
of employees for clarity in the output.
FROM Employees: This specifies the table from which to retrieve the
data.
GROUP BY Department: This groups the results by the Department
column, allowing the COUNT(*) function to count employees in each
department separately.
Executing this query will return a list of departments along with the number of
employees in each department.
32
Explanation:
SELECT Department: This retrieves the names of the departments.
MAX(Salary): This calculates the maximum salary for each department.
AS MaxSalary: This provides an alias for the resulting maximum salary
column.
FROM Employees: This specifies the table from which to retrieve the
data.
GROUP BY Department: This groups the results by the Department
column, allowing the MAX(Salary) function to compute the maximum
salary for each department.
HAVING MAX(Salary) > 60000: This condition filters the results to
include only those departments where the maximum salary exceeds
60,000.
Executing this query will return a list of departments with their maximum
salaries, but only for those departments where the maximum salary is greater
than 60,000.
33
Q23. Write a query to select all employees and order them by LastName in
ascending order.
Example: SELECT * FROM Employees ORDER BY LastName ASC;
Explanation:
SELECT *: This selects all columns from the Employees table.
FROM Employees: This specifies the table from which to retrieve the
data.
ORDER BY LastName ASC: This orders the results by the LastName
column in ascending order. The ASC keyword is optional since ascending
order is the default.
Executing this query will return all employees sorted by their last names
in alphabetical order.
34
Q24. Write a query to display employees from the IT department ordered by
their Salary in descending order.
Example: SELECT * FROM Employees WHERE Department = 'IT'
ORDER BY Salary DESC;
Explanation:
SELECT *: This selects all columns from the Employees table.
FROM Employees: This specifies the table from which to retrieve the
data.
WHERE Department = 'IT': This condition filters the results to include
only employees in the IT department.
ORDER BY Salary DESC: This orders the results by the Salary column
in descending order, so that the highest salaries appear first.
Executing this query will return all employees from the IT department,
sorted by their salary from highest to lowest.
35
Q25. Write an SQL query to create a table named Students with the following
structure:
StudentID (INT, Primary Key)
FirstName (VARCHAR)
LastName (VARCHAR)
Age (INT)
Gender (VARCHAR)
Grade (DECIMAL)
EnrollmentDate (DATE)
Explanation:
CREATE TABLE Students: This command starts the creation of a new
table named Students.
StudentID INT PRIMARY KEY: This defines the StudentID column as
an integer and sets it as the primary key, ensuring that each value in this
column is unique.
FirstName VARCHAR(50): This defines the FirstName column as a
variable character string with a maximum length of 50 characters.
36
LastName VARCHAR(50): This defines the LastName column similarly
to FirstName, allowing up to 50 characters.
Age INT: This defines the Age column as an integer.
Gender VARCHAR(10): This defines the Gender column as a variable
character string with a maximum length of 10 characters.
Grade DECIMAL(5, 2): This defines the Grade column as a decimal
number that can have up to 5 digits in total, with 2 digits after the decimal
point.
EnrollmentDate DATE: This defines the EnrollmentDate column as a
date type.
Executing this query will create the Students table with the specified structure.
Explanation:
Each INSERT INTO statement adds a new record to the Students table with
values for the specified columns:
StudentID: Unique identifier for each student.
37
FirstName: The first name of the student.
LastName: The last name of the student.
Age: The age of the student.
Gender: The gender of the student.
Grade: The student's grade as a decimal value.
EnrollmentDate: The date the student enrolled, formatted as YYYY-
MM-DD.
Executing these commands will insert 10 records into the Students table.
To retrieve information from the students2 table using various conditions, you
can use SQL queries with WHERE, ORDER BY, GROUP BY, and other
clauses. Here are some examples:
1. Retrieve Students by Age
SELECT * FROM students2 WHERE Age > 20;
38
This query retrieves all female students.
3. Retrieve Students with a Specific Grade Range
SELECT * FROM students2 WHERE Grade BETWEEN 3.0 AND 4.0;
This query retrieves students whose grades are between 3.0 and 4.0.
39
This query retrieves students with grades higher than 3.5.
This query retrieves all students ordered by their enrollment date in ascending
order.
40
6. Count Students by Gender
SELECT Gender, COUNT(*) AS NumberOfStudents FROM students2 GROUP
BY Gender;
This query retrieves all students with the first name "John."
41
8. Retrieve Students with Specific Last Name
SELECT * FROM students2 WHERE LastName LIKE 'S%';
This query retrieves all students whose last name starts with "S."
Q28. Write a query to increase the grade of all female students by 5%.
Explanation
UPDATE students2: Specifies the table you want to update.
SET Grade = Grade * 1.05: Increases the current grade by 5%.
Multiplying by 1.05 effectively raises the grade by 5%.
WHERE Gender = 'Female': Ensures that only female students are
affected by this update.
42
Q29. Write a query to delete the record of the student with student id=3
Explanation
DELETE FROM students2: Specifies the table from which you want to
delete a record.
WHERE StudentID = 3: Conditions the deletion to only affect the
record where StudentID is 3.
Run this command in your SQL environment, and it will remove the student
record with StudentID = 3
Q30. Write a query to add a new column Email (VARCHAR) to the Students
table.
43
Explanation
ALTER TABLE students2: Specifies the table that you want to modify.
ADD Email VARCHAR(255): Adds a new column named Email with a
data type of VARCHAR and a maximum length of 255 characters.
Run this command in your SQL environment to add the Email column to the
students2 table. Let me know if you need any further assistance!
Q31. Write a query to group students by Gender and calculate the average grade
for each gender.
44
Q32. Discuss ER Modelling.
= ER (Entity-Relationship) modeling is a conceptual framework used to
describe the structure of a database. It helps to visually represent the
relationships between data entities (objects) and their attributes in a database.
ER modeling is an essential part of the database design process and is
commonly used to develop relational databases.
45
o In ER diagrams, attributes are typically represented by ellipses
connected to the entity.
o Example: The Student entity may have attributes such as
StudentID, FirstName, LastName, Age, and Email.
3. Primary Key:
o A primary key is an attribute or set of attributes that uniquely
identifies each record in an entity. It ensures that no two records
have the same value for this attribute.
o Example: StudentID can be a primary key in the Student entity,
ensuring each student has a unique identifier.
4. Relationships:
o A relationship represents an association between two or more
entities. It shows how entities are related to one another.
o In ER diagrams, relationships are represented by diamonds, and
lines are used to connect entities to relationships.
o Example: A Student can be enrolled in many Courses, and each
Course can have many Students. This represents a many-to-many
relationship.
5. Cardinality:
o Cardinality defines the number of instances of one entity that can
be associated with instances of another entity in a relationship. The
most common cardinality types are:
One-to-One (1:1): An entity in one set can be related to only
one entity in another set.
One-to-Many : An entity in one set can be related to
multiple entities in another set.
Many-to-Many: Entities in both sets can be related to
multiple entities in the other set.
46
o Example: In a Student and Course relationship, one student can be
enrolled in many courses , and many students can enroll in one
course (N:1), making it a many-to-many relationship.
6. Weak Entity:
o A weak entity is an entity that cannot be uniquely identified by its
own attributes and relies on another entity (called the "owner" or
"strong" entity) for its identification. A weak entity typically has a
partial key and a total participation relationship with its owner
entity.
o Example: In a university system, Dependent could be a weak entity
if it's used to represent dependents of employees, where the
identification of a dependent relies on the Employee entity.
7. Relationship Degree:
o The degree of a relationship refers to the number of entities
involved in the relationship. The most common degrees are:
Unary Relationship: A relationship involving only one
entity type (e.g., an employee supervises another employee).
Binary Relationship: A relationship involving two entities
(e.g., Student and Course).
Ternary Relationship: A relationship involving three
entities (e.g., a project that involves multiple Employees and
Departments).
ER Diagram (ERD):
An ER diagram is a graphical representation of an ER model that visualizes the
entities, attributes, relationships, and cardinalities. It is a key tool in database
design for planning and illustrating the structure of a database before
implementation.
47
Example of ER Modeling:
Let’s consider a university system as an example to illustrate an ER diagram:
Entities:
o Student: Attributes include StudentID (Primary Key), FirstName,
LastName, Age, Email.
o Course: Attributes include CourseID (Primary Key), CourseName,
Credits.
o Instructor: Attributes include InstructorID (Primary Key), Name,
Department.
Relationships:
o Enrollment: Represents the many-to-many relationship between
Student and Course.
o Teaches: Represents the one-to-many relationship between
Instructor and Course.
Steps in ER Modeling:
1. Identify Entities: Identify the main objects (entities) in the system.
2. Determine Relationships: Determine how these entities are related to
each other.
3. Define Attributes: Identify the key attributes for each entity and define
the primary key.
4. Specify Cardinality: Define the cardinality of relationships.
5. Draw the ER Diagram: Represent the entities, relationships, and
attributes visually.
48
Advantages of ER Modeling:
Clear Structure: It provides a clear, high-level view of the data and
relationships.
Simplicity: ER models are easy to understand and communicate, making
them suitable for non-technical stakeholders.
Data Integrity: ER models help ensure data integrity by defining
relationships and constraints.
Flexibility: ER diagrams can be easily modified during the design
process.
Conclusion:
ER modeling is a fundamental step in designing a database system, as it lays out
the blueprint for how data is structured and how entities interact with one
another. It forms the foundation for creating a well-organized, efficient, and
scalable relational database.
49
Entity Symbol Name Description
50
Relationship Symbol Name Description
51
Attribute Symbol Name Description
52
Conceptual Data Models establish a broad view of what should be included in
the model set. Conceptual ERDs can be used as the foundation for logical data
models. They may also be used to form commonality relationships between ER
models as a basis for data model integration. All of the symbols shown Above
are found in the Entity Relationship model.
DATE OF
BIRTH
NO.
CUSTOMER
AGE
53
ER diagram is known as Entity-Relationship diagram. It is used to analyze to
structure of the Database. It shows relationships between entities and their
attributes. An ER model provides a means of communication.
ER diagram of Bank has the following description :
This bank ER diagram illustrates key information about bank, including entities
such as branches, customers, accounts, and loans. It allows us to understand the
relationships between entities.
Entities and their Attributes are :
Bank Entity : Attributes of Bank Entity are Bank Name, Code and
Address.
Code is Primary Key for Bank Entity.
Customer Entity : Attributes of Customer Entity are Customer_id,
Name, Phone Number and Address.
Customer_id is Primary Key for Customer Entity.
Branch Entity : Attributes of Branch Entity are Branch_id, Name and
Address.
Branch_id is Primary Key for Branch Entity.
54
Account Entity : Attributes of Account Entity are Account_number,
Account_Type and Balance.
Account_number is Primary Key for Account Entity.
Loan Entity : Attributes of Loan Entity are Loan_id, Loan_Type and
Amount.
Loan_id is Primary Key for Loan Entity.
Relationships are :
55
Q35.ER DIAGRAM OF UNIVERSITY.
56
STREET: Street name.
CITY: City of residence.
STATE: State of residence.
PIN: Postal code.
2. COURSE
o Attributes:
COURSE_ID: Unique identifier for each course.
COURSE_NAME: Name of the course.
3. LECTURER
o Attributes:
LECTURER_ID: Unique identifier for each lecturer.
LECTURER_NAME: Name of the lecturer.
4. SUBJECTS
o Attributes:
SUBJECT_ID: Unique identifier for each subject.
SUBJECT_NAME: Name of the subject.
Relationships:
1. Attends (between STUDENT and COURSE)
o This is a many-to-many relationship, as each student can attend
multiple courses, and each course can have multiple students.
57
3. Teaches (between LECTURER and STUDENT)
o This is a one-to-many relationship, meaning one lecturer can teach
multiple students, but each student is taught by only one lecturer in
this context.
4. Teaches (between LECTURER and SUBJECTS)
o This is a one-to-many relationship, where each lecturer can teach
multiple subjects, but each subject is taught by only one lecturer.
5. Has (between COURSE and SUBJECTS)
o This is a one-to-many relationship, indicating that each course
consists of multiple subjects, but each subject belongs to only one
course.
Summary
This ER diagram models a university’s structure by defining entities (students,
courses, lecturers, subjects) and their relationships. It allows the tracking of
which students attend specific courses, what subjects they take, and which
lecturers are assigned to teach them. This structure could be useful for managing
student enrolments, lecturer assignments, and course structures within the
university.
58