Unit2-Relational Model-Part1
Unit2-Relational Model-Part1
UNIT-II
Part-1
Structure of Relational DB
, Database Schema, Keys
Structure of Relational DB
• Reference link:
https://www.ibm.com/docs/en/mfci/7.6.2?topic=design-relational-database-s
tructure
Relational DB
• Attribute data types
Each database record contains multiple attributes. Every attribute has an associated data type.
• Database views
A database view is a subset of a database and is based on a query that runs on one or more
database tables. Database views are saved in the database as named queries and can be used to
save frequently used, complex queries.
• Indexes
You can use indexes to optimize performance for fetching data. Indexes provide pointers to
locations of frequently accessed data. You can create an index on the columns in an object that
you frequently query.
• Primary keys
When you assign a primary key to an attribute, the key uniquely identifies the object that is
associated with that attribute. The value in the primary column determines which attributes are
used to create the primary key.
Example of a Relation
Basic Structure
• Formally, given sets D1, D2, …. Dn a relation r is a subset of
D1 x D2 x … x Dn
Thus, a relation is a set of n-tuples (a1, a2, …, an) where each ai Di
• Example: If
customer_name = {Jones, Smith, Curry, Lindsay}
customer_street = {Main, North, Park}
customer_city = {Harrison, Rye, Pittsfield}
Then r = { (Jones, Main, Harrison),
(Smith, North, Rye),
(Curry, North, Rye),
(Lindsay, Park, Pittsfield) }
is a relation over
customer_name x customer_street x customer_city
Attribute Types
• Each attribute of a relation has a name
• The set of allowed values for each attribute is called
the domain of the attribute
• Attribute values are (normally) required to be atomic;
that is, indivisible
• Note: multivalued attribute values are not atomic
• Note: composite attribute values are not atomic
• The special value null is a member of every domain
• The null value causes complications in the definition of
many operations
• We shall ignore the effect of null values in our main
presentation and consider their effect later
Relation Schema
• A1, A2, …, An are attributes
customer
Relations are Unordered
Order of tuples is irrelevant (tuples may be stored in an arbitrary order)
Example: account relation with unordered tuples
The customer Relation
The depositor Relation
Relational database schema
• a Relational database schema is an arrangement of relation states in
such a manner that every relational database state fulfills the integrity
constraints set on a relational database schema.
• A database schema includes a relational schema for each of its tables
and a set of integrity constraints
Relational database schema
Keys in RDBMS
• A key refers to an attribute/a set of attributes that help us identify a
row (or tuple) uniquely in a table (or relation).
• A key is also used when we want to establish relationships between
the different columns and tables of a relational database.
Types of Keys in DBMS
• Super Key
• Candidate Key
• Primary Key
• Alternate Key
• Foreign Key
• Composite Key
• Unique Key
Super Key
• A super key refers to the set of all those keys that help us uniquely
identify all the rows present in a table.
• It means that all of these columns present in a table that can identify
the columns of that table uniquely act as the super keys.
• A super key is a candidate key’s superset (candidate key has been
explained next).
• We need to pick the primary key of any table from the super key’s set
so as to make it the table’s identity attribute.
Candidate Key
• The candidate keys refer to those attributes that identify rows uniquely
in a table. In a table, we select the primary key from a candidate key.
Thus, a candidate key has similar properties as that of the primary
keys.
• In a table, there can be multiple candidate keys.
Primary Key