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

Unit II_K scheme_DMS

The document provides an overview of the Relational Database Management System (RDBMS), including its structure, key concepts, and constraints. It explains fundamental components like tables, records, keys, and integrity constraints, along with SQL query design for creating and managing relational databases. Additionally, it covers the Entity-Relationship (E-R) model for data modeling, detailing entities, attributes, relationships, and functional dependencies.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Unit II_K scheme_DMS

The document provides an overview of the Relational Database Management System (RDBMS), including its structure, key concepts, and constraints. It explains fundamental components like tables, records, keys, and integrity constraints, along with SQL query design for creating and managing relational databases. Additionally, it covers the Entity-Relationship (E-R) model for data modeling, detailing entities, attributes, relationships, and functional dependencies.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

DATABASE MANAGEMENT

SYSTEM
DMS(313302)
Unit II

Relational Data Model


2a. Explain the concept of RDBMS also appropriateness for the given problem

2b. Design normalized database structure in the given problem.

2c. Design SQL queries to create Relational database and apply in the given data
constraint

2d. Identify the operators for queries implementation of given problem.


2.1 Relational Structure
• Dr. E.F.Codd proposed the relational model for database system in 1970.
• RDBMS stands for Relational Database Management System. RDBMS is the basis
for SQL, and for all modern database systems like MS SQL Server, IBM DB2,
Oracle, MySQL, and Microsoft Access.
• A relational database is a collection of information that organizes data in predefined
relationships where data is stored in one or more tables (or "relations") of columns
and rows, making it easy to see and understand how different data structures relate
to each other.
What is a table?
• The data in an RDBMS is stored in database objects which are called as tables. This
table is basically a collection of related data entries and it consists of numerous
columns and rows.
• A table consists of two properties: columns and rows. While rows represent records,
the columns represent attributes.
Ex.
Emp_no Emp_name Dept salary
101 AAA Account 30000
105 BBB Manufacturing 50000
111 CCC sales 38000

What is field?
• A field is a column in a table that is designed to maintain specific information about
every record in the table.
• Every table is broken up into columns called fields. The fields in the EMPLOYEE table
consist of Emp_no, Emp_nm, Dept, salary.
What is a Record?
• A record is also called as a row of data is each individual entry that exists in
a table.
• For ex. there are 3 records in the above EMPLOYEE table. Following is a
single row of data or record in the CUSTOMERS table −
101 AAA Account 30000
• Entity
• An entity is a “thing” or “object” in the real world.
• An entity contains attributes, which describe that entity. So anything
about which we store information is called an entity.
• Entities are recorded in the database and must be distinguishable,
i.e., easily recognized from the group.
• For example: A student, An employee, or bank a/c, etc. all are
entities.
Entity
• Attribute: It refers to every column present in a table. The attributes
refer to the properties that help us define a relation.

E.g., Employee_ID, Student_Rollno, SECTION, NAME, etc.

• Tuple – It is a single row of a table that consists of a single record.

• Degree: It refers to the total number of attributes that are there in


the relation.
• Relation Schema: It represents the relation’s name along with its
attributes. E.g., EMPLOYEE (ID_NO, NAME, ADDRESS, ROLL_NO, AGE)
is the relation schema for EMPLOYEE. If a schema has more than 1
relation, then it is known as Relational Schema.

• Cardinality: The number of tuples in a relation is known as cardinality.


The EMPOYEE relation defined above has cardinality 4.

• Domain: All permitted values of the attribute is called as domain.


Attribute

Emp_no Emp_nm State


Tuple
101 James California
Cardinality
102 Jenny New York
107 Smith Texas

Degree

Domain
Emp_no= {101, 102, 103}
Emp_nm= {James, Jenny, Smith}
States= {California, New York, Texas}
Key concept
• Keys are very important part of Relational database model. They are used to
establish and identify relationships between tables and also to uniquely
identify any record or row of data inside a table.

• A Key is an single attribute or a group of attributes, which help you uniquely


identify a record or a row of data in a table
1. Candidate key:
 A Candidate key is an attribute or a set of attributes that identify each record in a
table or relation uniquely.
 In a relation, there may be a primary key or may not, but there may be a key or
combination of keys which uniquely identify the record. Such a key is called as
Candidate key.
A table could contain multiple candidate keys
 This key can not store a NULL
 It must contain Unique values
There can be more than one candidate keys for a table.
Example of Employee table :
Example :
2. Super key:
 An attribute or a set of attributes within a table that can be used to identify
row of data within a table.
 Set of any candidate key is a super key
Super key -Example
3. Primary key
 PRIMARY KEY in DBMS is a column or group of columns in a table
that uniquely identify every row in that table
 The Primary key can’t be a duplicate meaning the same value can’t
appear more than once in the table.
 A table cannot have more than one primary key.
 The primary key field cannot be NULL
 The value in a primary key column can never be modified or
updated if any foreign key refers to that primary key.
 Primary key is choose from set of candidate key
Primary Key example
Foreign key
• Foreign key represents relationship between two tables.
• The foreign key is useful in linking together two tables having
common column.
• It is also known as referential integrity constraint.
• It is an attribute or set of attributes that references to Primary key of
same table or another table
 A FOREIGN KEY is a field in one table that refers to the PRIMARY KEY in another table. That is the
field which act as primary key in one relation (table) and acts as ordinary key in another relation
(table) is called as foreign key.
 Student Table :

 Branch Table
Integrity Constraint
• Integrity means correctness and completeness of data. Constraints means
restriction.
• Integrity constraints means the mechanism used to prevent invalid data
entry into table.
• Integrity constraint are rules defined in a database to maintain data
accuracy, Consistency and reliability
Domain Integrity constraints
• A domain constraint defines the valid range of values that a
column can hold.

• It specifies a column’s data type, format, and allowable values.

•By enforcing domain constraints, data consistency and validity can


be ensured, preventing inappropriate or inconsistent data
insertion into a column.

•These rules apply to the data before data is inserted into table
and column.
1) Default constraint

• It is used to assign default value to the column.


• The default value is added to all new records if no other
value is specified.
Ex. :

Create table Student(Rollno number(5) , Stud_name varchar2(20),


stud_city varchar( 15) default ‘sangli’);
2) Not null constraint

• By default all columns allow null values, but when not null constraint is enforced for the column,
then that column does not allow null values.

• The NOT NULL constraint specifies that a column in a table must not contain any null values.

• It ensures that a particular attribute or field cannot be left empty or undefined for any record in
the table.

Syntax:
Create table <tableName> (column_name datatype(size) not null);
EX:
Create table Student(Rollno number(5) , Stud_name varchar2(20) not null);
3) Check constraint
• These constraints defines the condition that each row must satisfied.

• Single column can have multiple check constraints.

• The CHECK constraint explains a condition that must be satisfied for the values in a
columns. It allows you to limit the range of acceptable values based on a specific
condition or expression.

Syntax

Create table <table_name>(column_name datatype(size) check(condition));

Ex.

Create table Student(Rollno number(5), Stud_name varchar2(20), marks number(02)


check(marks > 40));
Entity Integrity Constraint
• The entity integrity constraint focuses on the uniqueness of primary
key values within a table.

• It ensures that a table’s primary key column(s) contains unique and


non-null values.

• This constraint guarantees the identification and differentiation of


individual records within a table.
Entity Integrity Constraint
Primary key constraint
 It prevents duplication of data values within column and also does not
allow null values.

Syntax:

Create table <table_name>(column_name datatype (size) CONSTRAINT


constraint name primary key);

Ex. Create table Student(Rollno number(5) constraint R_pk primary key,


Stud_name varchar2(20), marks number(2,2));
Referential Integrity Constraint
• The referential integrity constraint establishes relationships between
tables by enforcing consistency in related data.

• It ensures that one table’s values in a foreign key column(s)


correspond to the primary key values in another table.

• This constraint maintain integrity of data associations between tables.


Referential Integrity Constraint
Foreign key constraint
• Also called Referential Integrity Constraint.
• Develops parent-child relationship between two tables.
• value of foreign key is derived from primary key of parent table.
• Primary key is present in parent table and foreign key is present in
child table.
Syntax:
Create table <table_name>( column_name datatype (size), foreign
key(column_name) references parent table_name(column_name));
Ex :
Create table department( empno number (5), foreign key(emp_no)
references emp(emp_no));
Foreign key – Insert Update Delete
• create table <table_name>
(column_name data_type, column_name data_type constraint
constraint_name references parent_table_name
(parent_table_col_name on delete cascade, column_name
data_type);
Key Constraint
• The key constraint determines the uniqueness of values within a
column or a combination of columns.

• It can be applied to designate a candidate key or a primary key.

• The key constraint prevents duplicate values in the specified


column(s) and ensures that each record can be uniquely identified.
Key Constraint
1. Unique Key Constraint
• It is used to prevent duplicate data entry within specified column.
• The UNIQUE constraint ensures that the values in a specific column(s) are
unique across all the records in a table.
• It allows for the insertion of null values. However, it allows only one
instance of a non-null value.

Syntax:
Create table table_name(ColumnName datatype(size) unique);
EX:
Create table Student(Rollno number(5) unique, Stud_name varchar2(20));
Data modeling using E-R model
• ER model stands for an Entity-Relationship model. It define relationship among
different entities
• It is a graphical Graphical representation of database.
• Relational Model  Defines one entity and its objects
Entity-Relationship model  Connects different entities as per their
relationship
Features:
 It is used to give structure to the data.
It simple and easy for understanding.
It can be easily converted into table.
 Good database design can be prepared using E-R model.
Symbols used to draw E-R model
Symbol Meaning

Entity(strong entity)

Weak entity

Attribute

Multivalued attribute

Derived attribute
Symbols used to draw E-R model
Symbol Meaning
Primary key attribute
_______

Relationship

Weak relationship
Components of E-R modeling
1. Entity:
 An entity is any object in the system that we want to store in the database.(any thing
about which data are to be collected and stored)
• Group of same type of entities are called entity sets.
Two types:
a) Strong Entity set:
The entity which is not depend on any other entity for its existence or entity which has
sufficient attribute to form a primary key.

b) Weak Entity set:


The entity which is depend on other entity for its existence or entity which do not has
sufficient attribute to form a primary key.
• Attribute and its type
 The properties of entity is called as attribute.
Types of attribute:
1. Single valued attribute:
Attribute that holds exactly one value is called as single valued attribute.
Ex. Student age , Aadhar number
2. Multi valued attribute:
Attribute which has more than one value for particular entity is called as multi
valued attribute.
Ex. Phone number of a student
: Landline and mobile.

3. Simple attribute:
An attribute that cannot be further subdivided into components is a simple
attribute.
Example: The roll number of a student, the ID number of an employee
4. Composite attribute:
• An attribute that can be split into subparts is a composite attribute.
(It can be divided into sub parts)
• Example: The address can be further split into house number, street
number, city, state, country, and pin code, the name can also be split
into first name middle name, and last name.
5. Derived attribute:
• An attribute that can be derived from other attributes is derived attributes. And it is
represented by dotted oval shape.
• Example: Total and average marks of a student, age of an employee that is derived
from date of birth.
6. Key attribute
• Key attributes are those attributes that can uniquely identify the entity in
the entity set.
Example: Roll-No is the key attribute because it can uniquely identify the
student.

7. Null Attribute
• This attribute can take NULL value when entity does not have value for it.
Example –The ‘Net Banking Active ’ attribute gives weather particular customer
having net banking facility activated or not activated.
• For bank which does not offer facility of net banking in customer table ‘Net
Banking Active’ attribute is always null till Net banking facility is not activated as
this attribute indicates Bank offers net banking facility or does not offers.
8. Complex Attribute
• Those attributes, which can be formed by the nesting of composite and
multi-valued attributes, are called “Complex Attributes“. These
attributes are rarely used in DBMS
• Example: Address because address contain composite value like street,
city, state, PIN code and also multi valued because one people has more
that one house address.
Relationship
• A relationship is used to describe the relation between entities. Diamond is used
to represent the relationship

• Types of relationship are as follows:


1. One-to-One Relationship
2. One-to-many relationship
3. Many-to-one relationship
4. Many-to-many relationship
Types of Relation
1. One-to-One Relationship:
• When only one instance of an entity is associated with the relationship, then it is
known as one to one relationship.
• For example :

Person Has Passport


2. One-to-many relationship
• When only one instance of the entity on the left, and more than one instance of an
entity on the right associates with the relationship then this is known as a one-to-many
relationship.
• For example, Scientist can invent many inventions, but the invention is done by the only
specific scientist.

3. Many-to-one relationship
• When more than one instance of the entity on the left, and only one instance of
an entity on the right associates with the relationship then it is known as a many-
to-one relationship.
• For example, Student enrolls for only one course, but a course can have many
students.
4. Many-to-many relationship
• When more than one instance of the entity on the left, and more than one instance of an entity
on the right associates with the relationship then it is known as a many-to-many relationship.
• For example, Employee can assign by many projects and project can have many employees.
Teacher_name
Roll_no Student_name
Contact_no
Teacher_ID

Teacher Teaches Student

Email_ID D.O.B Age Address


ER Model
Functional dependencies
• Definition : It is a method which describes relationship between the
attributes
• Attribute ‘B’ of relation R is functionally dependent on attribute ‘A’ of
relation R if and only if each value of A is associated with exactly one
value of B.
• It is denoted by A B this means that B is functionally dependent on A
or A determines B.
Rollno Studname

1 Ashish

2 Anurag

3 Varun

4 Rucha
Functional dependencies
• F(a) b • Definition :
•A B , it is called as A A Functional Dependency is a
determines B constraint that specifies the
• In Functional dependency An relationship of one attribute to
Attribute which determines another attribute in a Relation or
other Attribute is called a Table
Determinant Attribute.
• Attribute which determined by That is
Determinant is called A Determines B is represented by
Dependent Attribute.
A B
Functional Dependency Example
Rollno Student_Name Dept_Name Dept_Build • Functional Dependency :
ing
Rollno {Student_Name, Dept_Name,
2 Amit CS A4 Dept_Building}
3 Geeta IT A3
Case 1:
4 Ashish CS A4
Ex. : 3 {Geeta, IT, A3}
5 Ashish IT A3
Detarminant Dependant
6 Yusuf EC B2 1 A
2 B
7 Shreyas ME B2
Valid Functional Dependency
Functional Dependency Example
Rollno Student_Name Dept_Name Dept_Build • Functional Dependency :
ing
Dept_Name Dept_Building
2 Amit CS A4

3 Geeta IT A3 Case 2:
4 Ashish CS A4
Ex. : CS A4
CS A4
5 Ashish IT A3
Detarminant Dependant
6 Yusuf EC B2 1 A
1 A
7 Shreyas ME B2
Valid Functional Dependency
Functional Dependency Example
Rollno Student_Name Dept_Name Dept_Build • Functional Dependency :
ing
Dept_Name Dept_Building
2 Amit CS A4
Case 3: Determinant Dependant
3 Geeta IT A3 Ex. : EC B2
1 A
4 Ashish CS A4
ME B2 2 A
Valid Functional
5 Ashish IT A3 Dependency

6 Yusuf EC B2 Rollno Student_Name


7 Shreyas ME B2
Case 3:
Ex : 4 Ashish
5 Ashish
Functional Dependency Example
Rollno Student_Name Dept_Name Dept_Build • Functional Dependency :
ing
Student_Name Dept_Name
2 Amit CS A4
Case 4 :
3 Geeta IT A3 Ex. : Ashish CS
4 Ashish CS A4
Ashish IT

5 Ashish IT A3
Determinant Dependant

6 Yusuf EC B2 1 A
1 B
7 Shreyas ME B2
Invalid Functional Dependency
Functional Dependency
Fully functional dependency
• An attribute is fully functional dependent on another attribute, if it is
Functionally Dependent on that attribute and not on any of its proper
subset

• When one attribute is depends on combination of two or more


attribute then it is Fully Functional Dependency

• If Functional Dependency Set of A,B determines C and C cannot be


determined by subset of A, B then only we say that C is Fully Functional
dependent on {A, B}

• It is represented as {A, B} C
Fully Functional Dependency Example -1
StudID Course_ID Marks • Fully Functional Dependency :
{A, B} C
1 Amit 87
ex : {STUDENTID, COURSEID} MARKS
1 Geeta 82 STUDENTID MARKS
1 Ashish 91
COURSEID MARKS

2 Amit 77

2 Geeta 81

2 Ashish 75
Multi valued Functional Dependency
• A {B, C}
• Consider functional dependency , A {B, C} is Multi valued
dependency if there is no functional dependency between
dependents B and C , that is there should not be any functional
dependency

• B C (B cannot determines C ) or C B (C cannot determine B)


then only we can say that A Determines B and C is a Multi valued
Dependency
Multi valued Dependency Example -1
EMPID NAME AGE • Multi valued Dependency :
A {B, C}
1 Amit 54
ex : EMPID {NAME, AGE}
2 Geeta 25 NAME AGE
3 Ashish 28
AGE NAME
Dependency is represented by
4 Yusuf 25
EMPID NAME
5 Ashish 35 EMPID AGE
6 Shreyas 22
Multi valued dependency Example 2
• Multivalued dependency occurs when relation contains at least 3
columns.
• Bike_model {Manufacturing_yr, color}
• It is represented by
Bike_model Manufacturing_yr
Bike_model Color Bike_model Manufacturing_yr color
M1001 2007 Black
M1001 2007 Red
M1002 2008 Black
M1002 2008 Red
M1003 2009 Black
M1003 2009 Red
Transitive Functional dependency
• A transitive dependency occurs only when relation has minimum 3 or more
attributes.

• Let A, B, C are three distinct attributes, if we have A primary key and non key
attributes B and C where, C is more dependent upon B than A (B->C) and B is
directly dependent on A (A->B) then C can be considered as transitively dependent
on A.

• So, A-> C is transitive dependency.

• Definition : If there is functional dependency A B and B C & both are valid


dependency then A can determines C according to Transitive dependency
Transitive Functional Dependency Example
EMPID NAME Deptname DeptBuilding • Transitive Functional Dependency :

1 Raj R&D Building A


ex : EMPID DeptName
2 Anurag Design Building B DeptName DeptBuilding

3 Geeta Production Building C EMPID DeptBuilding is


“Transitive functional dependency”
4 Sacin Accounts Building D
2.3 Normalization

• Normalization is the process of refining database. So that the data access


speed is improved and integrity is increased.

Normalization can be defined as the process of eliminating redundancy


present in relational data by splitting or decomposing a table into small size
tables which is lossless.
Need of normalization
E_ID name Age Dept_id Dept_name Dept_head Dept_phone

1 Abc 34 7 Design Pqr 123

2 Mno 27 7 Design Pqr 123

3 Xyz 26 10 Production Tuv 987

4 Slr 40 10 Production Tuv 987

5 Smg 35 3 R&D Ksi 555

6 dmr 29 3 R&D ksi 555


Anomalies
• Insertion Anomalies :
If User want to add new sports it is not possible to add only sports. It
needs to write student details also. This is called as Insert Anomalies.

• Delete Anomalies:
If User want to delete any sports the entire record will be deleted.
This is called as Delete Anomalies.

• Update Anomalies:
Due to this anomalies original contents of entire data will be changed
EMP table Department Table
E_ID name Age Dept_id Dept_name Dept_head Dept_phone
1 Abc 34 7 Design Pqr 123
2 Mno 27 7 Design Pqr 123
3 Xyz 26 10 Production Tuv 987
4 Slr 40 10 Production Tuv 987
5 Smg 35 3 R&D Ksi 555
6 dmr 29 3 R&D ksi 555
Normal forms
1NF (First normal form)
• The relation said to be in 1NF if values in the domain of each attribute are
atomic.
• It does not allow multivalued attribute and composite attribute.
• Ex. Supplier_info

S_no S_name location P_no Quantity

S1 ABC Mumbai P1 200

S2 PQR Pune P2,P3 100,300

S3 RST Delhi P2,P1 100,100


What to do If Table is not in 1NF
• Composite Attribute

ID NAME Mobile no. ID FirstName MiddleName LastName MobileNo

EmpID Address EmpID HouseNo StreetName City Pin-code


142 105, GM Street, Mumbai, 400012 142 105 GM Street Mumbai 400012
• Multi valued Attribute
S_no S_name location P_no Quantity
S1 ABC Mumbai P1 200
S2 PQR Pune P2,P3 100,300
S3 RST Delhi P2,P1 100,100

S_no S_name location P_no Quantity


S1 ABC Mumbai P1 200
S2 PQR Pune P2 100
S2 PQR Pune P3 300
S3 RST Delhi P1 100
S3 RST Delhi P2 100

Is In First Normal Form


2NF (Second Normal Form)
• A relation is said to be in 2NF, if it is in 1NF and all the non key attributes
are fully functionally dependent on primary key.

S_no S_name Location S_no P_no quantity


S1 P1 200
S1 ABC Mumbai
S2 P2 300
S2 PQR Pune S2 P3 200
S3 RST Delhi S3 P1 100
s3 p2 100
3NF (Third normal form)
• A table said to be in 3NF, if it is in 2NF and every non key column
should be non transitively dependent on its primary key.

• This can be removed in 3NF by removing the column which is


dependent on non key column to another table.
Emp_ID Emp_Name Project_ID Project Emp_ID Emp_Name Project_ID
_Name
1 ABC 123
1 ABC 123 X
2 DEF 789
2 DEF 789 Z
3 GHI 123
3 GHI 123 X
4 JKL 123
4 JKL 123 X
5 MNO 789
5 MNO 789 Z
6 PQR 789 Z 6 PQR 789

7 STU 123 X 7 STU 123

Functional Dependencies :
Emp_ID Emp_Name, Project_ID

Project_ID Project_Name
123 X
789 Z

Functional Dependencies :
Project_ID Project_Name

You might also like