DBMS Module-2 P-2 Notes
DBMS Module-2 P-2 Notes
The principles of the relational model were first outlined by Dr. E.F. Codd in 1970 in a classic paper called
“A relational Model of Data for Large Shared Data Banks”. In this paper, Dr. Codd proposed the
relational model for the database.
The more popular models used at the time were hierarchical and network, or even simple flat file data
structures. Relational database management systems soon became very popular especially for their
ease of use and flexibility in structure. In addition, a number of innovative vendors, such as Oracle,
supplemented the RDBMS with a suite of powerful application development and user products,
providing a total solution.
Database
EMP DEPT
For Example, you might want to store information about all the employees in your company. In a
relational database, you create several tables to store different pieces of information about your
employees, such as an employee table, a department table and a salary table
Informal Definitions
Example of a Relation
The data type describing the types of values that can appear in each columns is called a domain.
Key of a Relation:
Each row has a value of a data item (or set of items) that uniquely identifies that row in
the table called the key
Eg:- In the STUDENT table, SSN is the key.
Sometimes row-ids or sequential numbers are assigned as keys to identify the rows in a
table called artificial key or surrogate key
Characteristics of Relations
Ordering of tuples in a relation r(R):
Tuples ordering is not part of a relation definition because it is defined as a set of tuples.
Many logical orders can be specified on the relation.
There is no preference for one logical ordering over another.
When a relation is implemented as a file, a physical ordering may be specified on the
records of the file.
Ordering of values within each tuple:
The tuple is an ordered list, so the ordering of values in a tuple is important.
At a logical level, the order is not important as long as the correspondence between the
attribute and its value is mentioned.
- For example, schema of the STUDENT relation interprets that, a student entity has Name,
Schema-based constraints
Transition constraints
Ex: the salary of an employee can only increase. Such constraints typically enforced by
the application programs or specified using active rules and triggers.
Operation
Insert <‘Alice’, ’J’, ‘Zelaya’, ‘999887777’, ‘1986-04-05’, ‘#334, Bangalore’, F,
Operation
Insert <‘Cecilia’, ’F’, ‘Kolonsky’, ‘677678989’, ‘1986-04-05’, ‘#454, Bangalore’,
Operation
Delete the EMPLOYEE tuple with SSN= ‘999887777’.
Operation
Result: Acceptable
Operation
Operation
Update the SSN of the EMPLOYEE tuple with SSN=‘999887777’ to ‘987654321’.
ER-to-Relational Mapping
Step 1
» For each regular entity type E in the ER schema, create a relation R that includes all the simple
attributes of E
» If the chosen key was a composite, the set of simple attributes that form it will together be the
primary key of R.
Step 2
» For each weak entity type W in the ER schema with owner entity type E, create a relation R that
includes all simple attributes (or simple components of composites) of W.
» Include as foreign key attributes of R the primary key attribute of the relation that corresponds to the
owner entity type E.
» The primary key of R is the combination of the primary key of the owner and the partial key of the
weak entity type, if any.
Step 3
» For each binary 1:1 relationship type R in the ER schema, identify the relations S and T that
correspond to the entity types participating in R.
» Choose one of the relations (say S). Include as a foreign key in S the primary key of T.
» It is better to choose an entity type with total participation in R for the role of S.
Step 4
» For each binary 1:N relationship type R, identify the relation S that represents the entity type
participating at the N-side of the relationship
» Include as a foreign key in S the primary key of the relation T that represents the other entity type
participating in R.
» For each binary M:N relationship type R, create a new relation S to represent R.
» Include as foreign key attributes in S the primary keys of the participating entity types.
Step 6
» R will include an attribute corresponding to A, plus the primary key attribute K of the relation that has
A as an attribute.
Step 7
» For each n-ary relationship type R, where n>2, create a new relation S.
» Include as foreign key attributes in S the primary keys of the relations that represent the participating
entity types
The ER model is convenient for representing an initial, high-level database design. Given an ER diagram
describing a databa'3e, a standard approach is taken to generating a relational database schema that
closely approximatesthe ER design. We now describe how to translate an ER diagram into a collection of
tables with associated constraints, that is, a relational database schema.
An entity set is mapped to a relation in a straightforward way: Each attribute of the entity set becomes
an attribute of the table. Note that we know both the domain of each attribute and the (primary) key of
an entity set.
A relationship set, like an entity set, is mapped to a relation in the relational model.
To represent a relationship, we must be able to identify each participating entity and give values to the
descriptive attributes of the relationship. Thus, the attributes of the relation include:
• The primary key attributes of each participating entity set, as foreign key fields.
The set of nondescriptive attributes is a superkey for the relation. If there are no key constraints, this set
of attributes is a candidate key.
CREATE TABLE Works_In2 ( ssn CHAR(11), did INTEGER, address CHAR(20) , since DATE, PRIMARY KEY
(8sn, did, address), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (address) REFERENCES
Locations, FOREIGN KEY (did) REFERENCES Departments);
The following SQL statement, defining a DepLMgr relation that captures the information in both
Departments and Manages, illustrates the approach to translating relationship sets with key constraints:
CREATE TABLE DepLMgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR (11) , since DATE,
PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees)
Consider the ER diagram in Figure 3.13, which shows two relationship sets, Manages and "Works_In.
Every department is required to have a manager, due to the participation constraint, and at most one
manager, due to the key constraint.
A weak entity set always participates in a one-to-many binary relationship and has a key constraint and
total participation.we must take into account that the weak entity has only a partial key. Also, when an
owner entity is deleted, we want all owned weak entities to be deleted.
CREATE TABLE Dependents (pnameCHAR(20) , age INTEGER, policyid INTEGER, PRIMARY KEY (pname,
policyid), FOREIGN KEY (policyid) REFERENCES Policies ON DELETE CASCADE);