Unit-3: Relational Database Model
Unit-3: Relational Database Model
Unit-3: Relational Database Model
RJU
Unit-3
Dept. of B.Sc.CSIT
University Campus, RJU
[email protected]
9844071035
Structure of RDBMS and terminology
A Relational Database management System(RDBMS) is a database management system based
on the relational model introduced by E.F Codd. In relational model, data is stored
in relations(tables) and is represented in form of tuples(rows).
RDBMS is used to manage Relational database. Relational database is a collection of organized
set of tables related to each other, and from which data can be accessed easily. Relational
Database is the most commonly used database these days.
Terminologies uses in RDBMS:-
Table
Tuple
Attribute
Relational schema
Relational key
Integrity constraints
Terminologies contd…
Table
In Relational database model, a table is a collection of data elements organised in terms of rows and
columns. A table is also considered as a convenient representation of relations. But a table can have
duplicate row of data while a true relation cannot have duplicate data. Table is the most simplest form of
data storage. Below is an example of an Employee table.
ID Name Age Salary
1 Adam 34 13000
2 Alex 28 15000
3 Stuart 20 18000
4 Ross 42 19020
Tuple
A single entry in a table is called a Tuple or Record or Row. A tuple in a table represents a set of related
data. For example, the above Employee table has 4 tuples/records/rows.
Following is an example of single record or tuple.
1 Adam 34 13000
Terminologies contd…
Attribute
A table consists of several records(row), each record can be broken down into several smaller parts of data
known as Attributes. The above Employee table consist of four attributes, ID, Name, Age and Salary.
Attribute Domain
When an attribute is defined in a relation(table), it is defined to hold only a certain type of values, which is
known as Attribute Domain.
Hence, the attribute Name will hold the name of employee for every tuple. If we save employee's address
there, it will be violation of the Relational database model.
Name
Adam
Alex
Stuart - 9/401, OC Street,
Amsterdam
Ross
Terminologies contd…
Relation schema
A relation schema describes the structure of the relation, with the name of the relation(name of table), its
attributes and their names and type.
Relation key
A relation key is an attribute which can uniquely identify a particular tuple(row) in a relation(table).
Database schema
The data which is stored in the database at a particular moment of time is called an instance of
the database.
The overall design of a database is called schema.
A database schema is the skeleton structure of the database. It represents the logical view of
the entire database.
A schema contains schema objects like table, foreign key, primary key, views, columns, data
types, stored procedure, etc.
A database schema is designed by the database designers to help programmers whose
software will interact with the database. The process of database creation is called data
modeling.
Schema diagram
A database schema can be represented by using the visual diagram. That diagram shows the
database objects and relationship with each other.
A schema diagram can display only some aspects of a schema like the name of record type,
data type, and constraints. Other aspects can't be specified through the schema diagram. For
example, the given figure neither show the data type of each data item nor the relationship
among various files.
In the database, actual data changes quite frequently.
For example, in the given figure, the database changes
whenever we add a new grade or add a student.
The data at a particular moment of time is called the
instance of the database.
Keys
KEYS in DBMS is an attribute or set of attributes which helps you to identify a row(tuple) in a
relation(table).
They allow you to find the relation between two tables.
Keys help you uniquely identify a row in a table by a combination of one or more columns in
that table.
Key is also helpful for finding unique record or row from the table.
ID Name Age Salary
1 Adam 34 13000
2 Alex 28 15000
3 Stuart 20 18000
4 Ross 42 19020
In the above table ID is the key column which uniquely identifies each record of the table.
Keys continue
Need of key in table in RDBMS
Keys help to identify any row of data in a table. In a real-world application, a table could contain thousands
of records. Moreover, the records could be duplicated. Keys in RDBMS ensure that you can uniquely identify
a table record despite these challenges.
Allows to establish a relationship between and identify the relation between tables
Help to enforce identity and integrity in the relationship.
Types of Keys in DBMS (Database Management System)
Super Key
Primary Key
Candidate Key
Alternate Key
Foreign Key
Composite Key
Surrogate Key
Super key
A super key is a group of single or multiple keys which identifies rows in a table.
A Super key may have additional attributes that are not needed for unique identification.
Two rows can’t have the same primary key value xyz@gmai
2 12 Nick Wright
l.com
It must for every row to have a primary key value.
mno@yah
The primary key field cannot be null. 3 13 Dana Natan
oo.com
The value in a primary key column can never be modified or updated if any foreign key refers to that primary
key.
In this example, OrderNo and ProductID can’t be a primary key as it does not uniquely identify a record. However, a
composite key of Order ID and Product ID could be used as it uniquely identified each record.
SURROGATE KEYS
SURROGATE KEYS is An artificial key which aims to uniquely identify each record is called a
surrogate key. This kind of partial key in DBMS is unique because it is created when you don’t
have any natural primary key. They do not lend any meaning to the data in the table. Surrogate
key in DBMS is usually an integer. A surrogate key is a value generated right before the record is
inserted into a table. Fname Lastname Start Time End Time
Anne Smith 09:00 18:00
Jack Francis 08:00 17:00
Anna McLean 11:00 20:00
Shown Willam 14:00 23:00
Above, given example, shown shift timings of the different employee. In this example, a surrogate key is
needed to uniquely identify each employee.
Surrogate keys in sql are allowed when no property has the parameter of the primary key.
In the table when the primary key is too big or complicated.
Difference Between Primary key & Foreign key
Following is the main difference between primary key and foreign key
Primary Key never accept null values. A foreign key may accept multiple null values.
Primary key is a clustered index and data in the A foreign key cannot automatically create an index,
DBMS table are physically organized in the sequence clustered or non-clustered. However, you can
of the clustered index. manually create an index on the foreign key.
You can have the single Primary key in a table. You can have multiple foreign keys in a table.