M3 Imp
M3 Imp
Guideline 1
Design a relation schema so that it is easy to explain its meaning
Do not combine attributes from multiple entity types and relationship types into a
single relation
If a relation schema corresponds to one entity type or one relationship type, it is
straightforward to interpret and to explain its meaning
If the relation corresponds to a mixture of multiple entities and relationships,
semantic ambiguities will result and the relation cannot be easily explained.
Both the relation schemas have clear semantics
A tuple in the EMP_DEPT relation schema represents a single employee but includes
additional information - the name (Dname) of the department for which the
employee works and the Social Security number (Dmgr_ssn) of the department
manager.
A tuple in the EMP_PROJ relates an employee to a project but also includes the
employee name (Ename), project name (Pname), and project location (Plocation).
Logically correct but they violate Guideline 1 by mixing attributes from distinct real-
world entities:
EMP_DEPT mixes attributes of employees and departments
EMP_PROJ mixes attributes of employees and projects and the WORKS_ON relationship
They may be used as views, but they cause problems when used as base relations.
GUIDELINE2:
Design the base relation schemas so that no insertion, deletion, or modification
anomalies are present in the relations
If any anomalies are present, note them clearly and make sure that the programs
that update the database will operate correctly
The second guideline is consistent with and, in a way, a restatement of the first
guideline
These guidelines may sometimes have to be violated in order to improve the
performance of certain queries.
Insertion Anomaly:
An insertion anomaly occurs when you cannot insert data into a table unless other
unrelated data is also present.
This is due to poor relational schema design where one table holds information about
multiple entities.
Insertion anomalies can be differentiated into two types, illustrated by the following
examples based on the EMP_DEPT relation:
1. To insert a new employee tuple into EMP_DEPT, we must include either the attribute
values for the department that the employee works for, or NULLs
- For example, to insert a new tuple for an employee who works in department number 5,
we must enter all the attribute values of department 5 correctly so that they are consistent
with the corresponding values for department 5 in other tuples in EMP_DEPT
- In the design of Employee in fig 1, we do not have to worry about this consistency
problem because we enter only the department number in the employee tuple; all other
attribute values of department 5 are recorded only once in the database, as a single tuple in
the DEPARTMENT relation
2. It is difficult to insert a new department that has no employees as yet in the EMP_DEPT
relation. The only way to do this is to place NULL values in the attributes for employee
- This violates the entity integrity for EMP_DEPT because Ssn is its primary key
- This problem does not occur in the design of Figure 1 because a department is entered in
the DEPARTMENT relation whether or not any employees work for it, and whenever an
employee is assigned to that department, a corresponding tuple is inserted in EMPLOYEE.
Deletion Anomalies:
The problem of deletion anomalies is related to the second insertion anomaly situation just
discussed
- If we delete from EMP_DEPT an employee tuple that happens to represent the last
employee working for a particular department, the information concerning that
department is lost from the database
- This problem does not occur in the database of Figure 2 because DEPARTMENT tuples are
stored separately.
Modification Anomalies:
In EMP_DEPT, if we change the value of one of the attributes of a particular
department say, the manager of department 5 we must update the tuples of all
employees who work in that department; otherwise, the database will become
inconsistent
If we fail to update some tuples, the same department will be shown to have two
different values for manager in different employee tuples, which would be wrong.
Q, What is a Normalization? Explain the 1NF, 2NF & 3NF with examples.
Normalization is a process of organizing data in a database to remove redundancy
(duplicate data) and avoid anomalies (problems during insert, update, or delete
operations).
Definition:
A relation is in 1NF if each column contains atomic (single) values and each record is unique.
There should be no multiple values in a single cell.
Example (1NF):
Definition:
A relation is in 2NF if it is in 1NF and every non-key attribute is fully dependent on the entire primary
key.
Example (2NF):
Student Table:
RollNo Name
101 Ravi
102 Meena
Enrollment Table:
RollNo Course
101 DBMS
101 Java
102 Python
Definition:
A relation is in 3NF if it is in 2NF and no non-key attribute is dependent on another non-key attribute.
All non-key attributes should depend only on the primary key.
Example (3NF):
Student Table:
Department Table:
DeptID DeptName
D02 Electronics
Q. Illustrate insert, delete, update, alter & drop commands in SQL.
🔹 1. INSERT Command:
Syntax:
Example:
🔹 2. DELETE Command:
Syntax:
Example:
🔹 3. UPDATE Command:
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;
Example:
UPDATE Students
SET Branch = 'ECE'
WHERE RollNo = 102;
🔹 4. ALTER Command:
Syntax Examples:
Add a new column:
Drop a column:
🔹 5. DROP Command:
Syntax:
Example:
✅ Summary Table:
Command Purpose
INSERT Add new data to a table
DELETE Remove data from a table
UPDATE Change existing data in a table
ALTER Change the structure of a table
DROP Delete the entire table and data
Q. Consider two sets of functional dependency. F={AC, ACD,
EAD, EH} E= {ACD, EAH}. Are they Equivalent?
➡ Armstrong’s Axioms are a set of rules used to infer all functional dependencies from a given set of
functional dependencies.
➡ These rules help in finding closure and are sound (correct) and complete.
1. Reflexivity:
If a set contains attributes, it can determine those same attributes.
2. Augmentation:
You can add extra attributes to both sides of a functional dependency.
3. Transitivity:
If A determines B and B determines C, then A determines C.
In SQL, datatypes define the type of data that can be stored in a column.
SQL uses the LIKE operator for pattern matching with wildcards:
% → Matches any number of characters (including zero characters)
_ → Matches exactly one character
✔ Examples:
✔ Example Query:
SELECT * FROM Employees
WHERE Name LIKE 'A%'; -- Names starting with A
SELECT * FROM Products
WHERE ProductName LIKE '%book'; -- Names ending with 'book'