0% found this document useful (0 votes)
12 views

DBMS Unit2

Uploaded by

bharathpatel612
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

DBMS Unit2

Uploaded by

bharathpatel612
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

DBMS: Database Management System

For B.Tech (CSE) II Year I Semester

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 :

1. Domain Integrity Constraint


2. Entity Integrity Constraint
3. Referential Integrity Constraint
4. Key Constraints
1. Domain Integrity Constraint
A domain integrity constraint is a set of rules that restricts the kind of attributes or
values a column or relation can hold in the database table. For example, we can specify
if a particular column can hold null values or not, if the values have to be unique or
not, the data type or size of values that can be entered in the column, the default
values for the column, etc.
2. Entity Integrity Constraint - This rule states that in any database relation value of
attribute of a primary key can't be null.
Entity Integrity Constraint is used to ensure the uniqueness of each record or row in the
data table. There are primarily two types of integrity constraints that help us in ensuring
the uniqueness of each row, namely, UNIQUE constraint and PRIMARY KEY
constraint.
The both Primary key & Unique key helps in uniquely identifying a record in the data
table. But unlike the primary key, a unique key can accept NULL values and it can be
used on more than one column of the data table.
3. Referential Integrity Constraint
Referential Integrity Constraint ensures that there always exists a valid relationship
between two tables. This makes sure that if a foreign key exists in a table relationship
then it should always reference a corresponding value in the second table or it should be
null.
Examples
Rule 1. You can't delete any of the rows in the ”Branch” relation that are visible since all the
”Branch” are in use in the “Student” relation.
Rule 2. You can't change any of the ”Branch_id” in the “Branch” relation since all the “Branch_id”
are in use in the ”student_1” relation.
Rule 3. The values that you can enter in the” Branch_id” field in the “student” relation must be in
the” Branch_id” field in the “Branch” relation.
Rule 4 You can enter a null value in the "student” relation if the records are unrelated.
4. Key Constraints
There are a number of key constraints in RDBMS that ensure that an entity or record is
uniquely identified in the database. There can be more than one key in the table but it
can have only one primary key.
Some of the key constraints in RDBMS are :
Primary Key Constraint
Foreign Key Constraint
Unique Key Constraint
Check Constraints
NOT NULL Constraints
Enforce Data Integrity by Database Constraints

What is data integrity?


Data integrity refers to the accuracy, consistency, and reliability of data that is stored in the
database. Both database designers and database developers are responsible for implementing
data integrity within one or a set of related databases

Types of Data Integrity


There are four types of data integrity:
Row integrity
Column integrity
Referential integrity
User-defined integrity
Row integrity
Row integrity refers to the requirement that all rows in a table must have a unique
identifier that can be used to tell apart each record. This unique identifier is normally
known as Primary Key of the table. A Primary Key can be formed by a single column or a
combination of multiple columns.
Column integrity
Column integrity refers to the requirement that data stored in a column must adhere to
the same format and definition. This includes data type, data length, default value of
data, range of possible values, whether duplicate values are allowed, or whether null
values are allowed.
For example, LastName in employees table must be varchar, max 20 characters long,
default to empty string, and can't be null.
Referential integrity

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

Prepared by K. Chandrasena chary, Dept. of CSE, SCIT, KNR.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy