Chap 2
Chap 2
• The two-tier DB architecture allows the client to communicate directly with the database-
thus making it less secure.
• The three-tier DB architecture does not allow its clients and database to communicate
directly- thus making it comparatively more secure in the long run.
In two-tier, the application logic is either In three-tier, the application logic or process
buried inside the user interface on the client resides in the middle-tier, it is separated from the
or within the database on the server (or both). data and the user interface.
Two-tier architecture consists of two layers: Three-tier architecture consists of three layers:
Client Tier and Database (Data Tier). Client Layer, Business Layer and Data Layer.
It results in performance loss whenever the It results in performance loss whenever the
users increase rapidly. system is run on Internet but gives more
performance than two-tier architecture.
Database Schema
• A database schema is a logical representation of data that shows how the data in a
database should be stored logically. It shows how the data is organized and the relationship
between the tables.
• Database schema contains table, field, views and relation between different keys
like primary key, foreign key.
• Data are stored in the form of files which is unstructured in nature which makes accessing
the data difficult. Thus, to resolve the issue the data are organized in structured way with
the help of database schema.
• Database schema provides the organization of data and the relationship between the stored
data.
• Database schema defines a set of guidelines that control the database along with that it
provides information about the way of accessing and modifying the data.
Integrity Constraints
Integrity constraints are the set of predefined rules that are used to maintain the quality of
information. Integrity constraints ensure that the data insertion, data updating, data deleting and
other processes have to be performed in such a way that the data integrity is not affected. They act
as guidelines ensuring that data in the database remain accurate and consistent. So, integrity
constraints are used to protect databases. The various types of integrity constraints are
Types of Integrity Constraints:
1. Domain Constraints
2. Not-Null Constraints
3. Entity integrity Constraints
4. Key Constraints
5. Primary Key Constrains
6. Referential integrity constraints
1. Domain Constraints
These are defined as the definition of valid set of values for an attribute. The data type of domain
include string, char, time, integer, date, currency etc. The value of the attribute must be available
in comparable domains.
Example:
2. Not-Null Constraints
It specifies that within a tuple, attributes overs which not-null constraint is specified must not
contain any null value.
Example:
Let, the not-null constraint be specified on the "Semester" attribute in the relation/table given
below, then the data entry of 4th tuple will violate this integrity constraint, because the "Semester"
attribute in this tuple contains null value. To make this database instance a legal instance, its entry
must not be allowed by database management system.
21CSE103 Mukesh 20
Mukesh 5th 20
4. Key Constraints
Keys are the entity set that are used to identify an entity within its entity set uniquely. An entity set
can contain multiple keys, bit out of them one key will be primary key. A primary key is always
unique, it does not contain any null value in table.
Example:
20 Chandigarh
21 Punjab
25 Delhi
3. Super Key
The set of attributes that can uniquely identify a tuple is known as Super Key.
• Adding zero or more attributes to the candidate key generates the super key.
• A candidate key is a super key but vice versa is not true.
• Super Key values may also be NULL.
Example:
Consider the table shown above.
STUD_NO+PHONE is a super key.
Relation between Primary Key, Candidate Key, and Super Key
4. Alternate Key
The candidate key other than the primary key is called an alternate key .
• All the keys which are not primary keys are called alternate keys.
• It is a secondary key.
• It contains two or more fields to identify two or more records.
• These values are repeated.
Example:
5. Foreign Key
If an attribute can only take the values which are present as values of some other attribute, it will
be a foreign key to the attribute to which it refers. The relation which is being referenced is called
referenced relation and the corresponding attribute is called referenced attribute. The referenced
attribute of the referenced relation should be the primary key to it.
• It is a key it acts as a primary key in one table and it acts as
secondary key in another table.
• It combines two or more relations (tables) at a time.
• They act as a cross-reference between the tables.
Example:
ER Model
Peter Chen developed the ER diagram in 1976. The Entity Relationship Model is a model for
identifying entities to be represented in the database and representation of how those entities are
related. The ER data model specifies enterprise schema that represents the overall logical structure
of a database graphically.
Why Use ER Diagrams In DBMS?
• ER diagrams represent the E-R model in a database, making them easy to convert into
relations (tables).
• ER diagrams provide the purpose of real-world modeling of objects which makes them
intently useful.
• ER diagrams require no technical knowledge and no hardware support.
• These diagrams are very easy to understand and easy to create even for a naive user.
• It gives a standard solution for visualizing the data logically.
Symbols Used in ER Model
Components of ER Diagram
Entity
An Entity may be an object with a physical existence – a particular person, car, house, or employee
– or it may be an object with a conceptual existence – a company, a job, or a university course.
Types of Entity
There are two types of entity:
1. Strong Entity
A strong entity is not dependent on any other entity in the schema. A strong entity will always have
a primary key. Strong entities are represented by a single rectangle. The relationship of two strong
entities is represented by a single diamond. Various strong entities, when combined together, create
a strong entity set
2. Weak Entity
A weak entity is dependent on a strong entity to ensure its existence. Unlike a strong entity, a weak
entity does not have any primary key. It instead has a partial discriminator key. A weak entity is
represented by a double rectangle. The relation between one strong and one weak entity is
represented by a double diamond. This relationship is also known as an identifying relationship.
For Example, A company may store the information of dependents (Parents, Children, Spouse)
of an Employee. But the dependents can’t exist without the employee. So Dependent will be
a Weak Entity Type and Employee will be Identifying Entity type for Dependent, which means
it is a strong entity type.
Attributes
Attributes are the properties that define the entity type. For example, Roll_No, Name, DOB, Age,
Address, and Mobile_No are the attributes that define entity type Student. In ER diagram, the
attribute is represented by an oval.
Types of Attributes
1. Key Attribute
The attribute which uniquely identifies each entity in the entity set is called the key attribute. For
example, Roll_No will be unique for each student. In ER diagram, the key attribute is represented
by an oval with underlying lines.
2. Composite Attribute
An attribute composed of many other attributes is called a composite attribute. For example, the
Address attribute of the student Entity type consists of Street, City, State, and Country. In ER
diagram, the composite attribute is represented by an oval comprising of ovals.
3. Multivalued Attribute
An attribute consisting of more than one value for a given entity. For example, Phone_No (can be
more than one for a given student). In ER diagram, a multivalued attribute is represented by a
double oval.
4. Derived Attribute
An attribute that can be derived from other attributes of the entity type is known as a derived
attribute. e.g.; Age (can be derived from DOB). In ER diagram, the derived attribute is represented
by a dashed oval.
The Complete Entity Type Student with its Attributes can be represented as:
3. Ternary Relationship: When there are three entity sets participating in a relationship, the
relationship is called a ternary relationship.
4. N-ary Relationship: When there is n entities set participating in a relationship, the relationship
is called an n-ary relationship.
Cardinality
The number of times an entity of an entity set participates in a relationship set is known
as cardinality . Cardinality can be of different types:
1. One-to-One: When each entity in each entity set can take part only once in the relationship, the
cardinality is one-to-one. Let us assume that a male can marry one female and a female can marry
one male. So, the relationship will be one-to-one.
the total number of tables that can be used in this is 2.
2. One-to-Many: In one-to-many mapping as well where each entity can be related to more than
one entity and the total number of tables that can be used in this is 2. Let us assume that one
surgeon department can accommodate many doctors. So, the Cardinality will be 1 to M. It means
one department has many Doctors. total number of tables that can used is 3.
3. Many-to-One: When entities in one entity set can take part only once in the relationship set and
entities in other entity sets can take part more than once in the relationship set, cardinality is many
to one. Let us assume that a student can take only one course but one course can be taken by many
students. So, the cardinality will be n to 1. It means that for one course there can be n students but
for one student, there will be only one course. The total number of tables that can be used in this
is 3.
4. Many-to-Many: When entities in all entity sets can take part more than once in the relationship
cardinality is many to many. Let us assume that a student can take more than one course and one
course can be taken by many students. So, the relationship will be many to many. the total number
of tables that can be used in this is 3.
Good Luck