DBMS Unit2
DBMS Unit2
Lecture by
K Chandrasena Chary
Associate Professor & TPO
Department of CSE,
Sree Chaitanya Institute of
Technological Sciences,
Karimnagar, Telangana
Mobile:9885744643
Mail: chandu518@gmail.com
Syllabus
Syllabus
UNIT – II Course Overview:
Introduction to Relational Model
• Relational Model
• Integrity Constraints
• Enforcing Integrity Constraints
• Querying Relational Data
• Logical Database design
• Introduction to views
• Introduction to Relational Algebra
• Tuple Relational Calculus
• Domain Relational Calculus
Introduction to Relational Model
Introduction:
Relational Model was proposed by E.F. Codd to model data in the form of relations or
tables. After designing the conceptual model of Database using ER diagram, we need to
convert the conceptual model in the relational model which can be implemented using any
RDBMS languages like Oracle SQL, MySQL.
What is Relational Model?
Relational Model represents how data is stored in Relational Databases. A relational
database stores data in the form of relations (tables). Consider a relation STUDENT with
attributes ROLL_NO, NAME, ADDRESS, PHONE and AGE
Relational Model (RM) represents the database as a collection of relations. A relation is
nothing but a table of values. Every row in the table represents a collection of related data
values.
Relational model basics
• Data is viewed as existing in two dimensional tables known as relations
• A relation (table) consists of unique attributes (columns) and tuples (rows)
• Tuples are unique
• Sometimes the value to be inserted into a particular cell may be unknown, or it may
have no value.
• This is represented by a NULL
• Null is not the same as zero, blank or an empty string
• Relational Database: Any database whose logical organization is based on relational
data model.
• RDBMS: A DBMS that manages the relational database
Relational Model Concepts
Attribute: Each column in a Table. Attributes are the properties which define a relation. e.g.,
Student_Rollno, NAME,etc.
Tables – In the Relational model the, relations are saved in the table format. It is stored along with its
entities. A table has two properties rows and columns. Rows represent records and columns represent
attributes.
Tuple – It is nothing but a single row of a table, which contains a single record.
Relation Schema: A relation schema represents the name of the relation with its attributes.
Degree: The total number of attributes which in the relation is called the degree of the relation.
Cardinality: Total number of rows present in the Table.
Column: The column represents the set of values for a specific attribute.
Relation instance – Relation instance is a finite set of tuples in the RDBMS system. Relation instances
never have duplicate tuples.
Relation key - Every row has one, two or multiple attributes, which is called relation key.
Attribute domain – Every attribute has some pre-defined value and scope which is known as attribute
Introduction to Integrity Constraints over Relations
• Integrity constraints in Database Management Systems (DBMS) are a set of rules
that are applied on the table columns or relationships to ensure that the overall
validity, integrity, and consistency (i.e. the quality) of the data present in the
database table is maintained.
• Each and every time a table insert, update, delete, or alter operation is performed,
it is evaluated against the rules mentioned in the integrity constraint.
• The data is inserted, updated, deleted, or altered only if the result of the constraint
comes out to be True. Thus, integrity constraint prevents accidental damage to the
database by an authorized user.
• Integrity constraints ensure that changes (update deletion, insertion) made to the
database by authorized users do not result in a loss of data consistency
Types of Integrity Constraints in DBMS
In Relational DBMS, We primarily have four types of Integrity Constraints, namely :
User-defined integrity
Data integrity is enforced by database constraints
Database Constraints are declarative integrity rules of defining table structures. They
include the following 7 constraint types:
Data type constraint:
This defines the type of data, data length, and a few other attributes which are specifically
associated with the type of data in a column.
Default constraint:
This defines what value the column should use when no value has been supplied explicitly
when inserting a record in the table.
Nullability constraint:
This defines that if a column is NOT NULL or allow NULL values to be stored in it.
Primary key constraint:
This is the unique identifier of the table. Each row must have a distinct value. The primary key
can be either a sequentially incremented integer number or a natural selection of data that
represents what is happening in the real world (e.g. Social Security Number). NULL values are
not allowed in primary key values.
Unique constraint:
This defines that the values in a column must be unique and no duplicates should be stored.
Sometimes the data in a column must be unique even though the column does not act as
Primary Key of the table. For example CategoryName column is unique in categories table but
CategoryName is not primary key of the table.
Foreign key constraint:
This defines how referential integrity is enforced between two tables.
Check constraint:
This defines a validation rule for the data values in a column so it is a user-defined data
integrity constraint. This rule is defined by the user when designing the column in a table.
Not every database engine supports check constraints. As of version 5.0, MySQL does not
support check constraint. But you can use enum data type or set data type to achieve some
of its functionalities that are available in other Relational Database Management Systems
(Oracle, SQL Server, etc).
Enforce Data Integrity by Database Constraints
Querying a Relational Data
SQL is a programming language that is used by most relational database management
systems (RDBMS) to manage data stored in tabular form (i.e. tables). A relational database
consists of multiple tables that relate to each other. The relation between tables is formed in
the sense of shared columns.
Query Language
In simple words, a Language which is used to store and retrieve data from database is
known as query language. For example – SQL
There are two types of query language:
1.Procedural Query language
2.Non-procedural query language
1. Procedural Query language:
In procedural query language, user instructs the system to perform a series of operations to
produce the desired results. Here users tells what data to be retrieved from database and how to
retrieve it.
2. Non-procedural query language:
In Non-procedural query language, user instructs the system to produce the desired result
without telling the step by step process. Here users tells what data to be retrieved from
database but doesn’t tell how to retrieve it .
Relational Algebra:
Relational algebra is a conceptual procedural query language used on relational model.
Relational Calculus:
Relational calculus is a conceptual non-procedural query language used on relational model.
Relational Algebra, Calculus, RDBMS & SQL:
• Relational algebra and calculus are the theoretical concepts used on relational model.
• RDBMS is a practical implementation of relational model.
• SQL is a practical implementation of relational algebra and calculus
Wish You All The Best