204 SQLUnit2
204 SQLUnit2
Data Models
A Database model defines the logical design and structure of a database and defines
how data will be stored, accessed and updated in a database management system.
Models are,
Hierarchical Model
Network Model
Entity-relationship Model
Relational Model
Hierarchical Model
Relational Model
The most popular and extensively used data model is the relational data model. The
data model allows the data to be stored in tables called relation.
The relations are normalized and the normalized relation values are known as atomic
values.
Each of the rows in a relation is called
tuples which contains the unique value.
The attributes are the values in each of the
columns which are of the same domain.
Relational DBMS is the most widely used
DBMS model because it is one of the
easiest. This model is based on
normalizing data in the rows and columns
of the tables. Relational model stored in
fixed structures and manipulated using
SQL.
Network Model
The conceptual data model describes the database at a very high level and is useful
to understand the needs or requirements of the database. It is this model, that is used
in the requirement-gathering process i.e. before the Database Designers start making
a particular database.
Weak Entity
An entity that depends on another entity called a weak entity. The weak entity
doesn't contain any key attribute of its own.
The weak entity is represented by a double rectangle.
strong entity
A strong entity is not dependent of any other entity in the schema. A strong
entity will always have a primary key. strong entities are represented by a single
rectangle
Attribute
The attribute is used to describe the property of an entity.
Eclipse is used to represent an attribute.
Attributes are also known as properties which define the entity type.
For example, Roll_No, Name, DOB, Age, Address, Mobile_No are the attributes
which defines entity type Student.
Types of an Attributes
1. Key Attribute Or single value Attribute
The attribute which uniquely identifies each
entity in the entity set is called key attribute.
For example, Roll_No will be unique for each
student. In ER diagram, key attribute is represented by an oval with
underlying lines.
2.Composite Attribute
An attribute composed of many other attribute is called as composite
attribute.
For example, Address attribute of
student Entity type consists of
Street, City, State, and Country.
In ER diagram, composite attribute
is represented by an oval
comprising of ovals.
3. Multivalued Attribute
An attribute consisting more than one
value for a given entity.
For example, Phone_No (can be more than one for a given student).
4. Derived Attribute
An attribute which can be derived from other
attributes of the entity type is known as derived
attribute.
e.g.; Age (can be derived from DOB).
In ER diagram, derived attribute is represented by dashed oval.
In ER diagram, multivalued attribute is represented by double oval.
Define relationship and relationship set AND types of relationship set.
Relationship is an association among 2 or more entities
Relationship set is a set of relationships of the same type.
Types of Relationship sets
Binary relationship set : Binary relationship set is a relationship set where two
entity sets participate in a relationship set.
Ternary relationship set : Ternary relationship set is a relationship set where three
entity sets participate in a relationship set.
Explain mapping cardinality.
Consider a binary relationship set R on entity sets A and B. There are four
possible mapping cardinalities in this case:
The mapping cardinality of a relationship set depends on the real world relationships
it is modeling.
Candidate Key: The minimal set of attribute which can uniquely identify a tuple
is known as candidate key. For Example, STUD_NO in STUDENT relation.
The value of Candidate Key is unique and non-null for every tuple.
There can be more than one candidate key in a relation. For Example, STUD_NO as
well as STUD_PHONE both are candidate keys for relation STUDENT.
The candidate key can be simple (having only one attribute) or composite as well.
For Example, {STUD_NO, COURSE_NO} is a composite candidate key for
relation STUDENT_COURSE.
Super Key: The set of attributes which can uniquely identify a tuple is known as
Super Key. For Example, STUD_NO, (STUD_NO, STUD_NAME) etc.
Primary Key: There can be more than one candidate key in a relation out of which
one can be chosen as primary key. For Example, STUD_NO as well as
STUD_PHONE both are candidate keys for relation STUDENT but STUD_NO can
be chosen as primary key (only one out of many candidate keys).
Alternate Key: The candidate key other than primary key is called as alternate
key. For Example, STUD_NO as well as STUD_PHONE both are candidate keys
for relation STUDENT but STUD_PHONE will be alternate key (only one out of
many candidate keys).
Foreign Key: If an attribute can only take the values which are present as values
of some other attribute, it will be foreign key to the attribute to which it refers. The
relation which is being referenced is called referenced relation and corresponding
attribute is called referenced attribute and the relation which refers to referenced
relation is called referencing relation and corresponding attribute is called
referencing attribute. Referenced attribute of referenced relation should be primary
key for it. For Example, STUD_NO in STUDENT_COURSE is a foreign key to
STUD_NO in STUDENT relation.
It may be worth noting that unlike, Primary Key of any given relation, Foreign Key
can be NULL as well as may contain duplicate tuples i.e. it need not follow
uniqueness constraint.
Unique key.
A unique key is a set of one or more than one fields of a table that uniquely identify
a record in a database table.
it is like primary key but it can accept null value and it cannot have duplicate values.
A key which has multiple attributes to uniquely identify rows in a table is called a
composite key. The difference between compound and the composite key is that any
part of the compound key can be a foreign key, but the composite key may or maybe
not a part of the foreign key.
Helps you to uniquely identify a It is a field in the table that is the primary
record in the table. key of another table.
Primary Key never accept null A foreign key may accept multiple null
values. values.
You can have the single Primary key You can have multiple foreign keys in a
in a table. table.