02 - Data Model - Language & Interfaces - Week 02
02 - Data Model - Language & Interfaces - Week 02
(d) Network Model: The network model extends the hierarchical model by
Data Models (contd)
represent entities, and edges represent relationships between them.
Example scenario could be situations where data needs to represent
multiple interconnections, like common Professors distributed across
various courses.
Instances :
The actual data in a database may change quite frequently. For example,
the database might changes every time we add a new student or enter a
new grade. The data in the database at a particular moment in time is
called a database state or snapshot. It is also called the current set of
occurrences or Instances in the database.
Schemas and Instances
(contd)
• In a given database state, each schema construct has its own current set
of instances; for example, the STUDENT construct will contain the set of
individual student entities (records) as its instances. Many database states
can be constructed to correspond to a particular database schema. Every
time we insert or delete a record or change the value of a data item in a
record, we change one state of the database into another state.
• When we define a new database, we specify its database schema only to
the DBMS.At this point, the corresponding database state is the empty
state with no data.
Schemas and Instances
• We get the(contd)
initial state of the database when the database is first
populated or loaded. From then on, every time an update operation is
applied to the database, we get another database state. At any point in
time, the database has a current state.
• The DBMS is partly responsible for ensuring that every state of the
database is a valid state i.e that is, a state that satisfies the structure
and constraints specified in the schema.
• Hence, specifying a correct schema to the DBMS is extremely important
and the schema must be designed with utmost care. The DBMS stores the
descriptions of the schema constructs and constraints—also called the
meta-data—in the DBMS catalog so that DBMS software can refer to
Thethe schema whenever
Three-Schema it needs to.
Architecture
The main goal of the three-schema architecture, is to separate the user
applications from the physical database. This model is designed to improve
data independence, and provide flexibility for the design and
implementation of database systems. The three levels of this architecture
are:
1. External Schema (View Level)
2. Conceptual Schema (Logical Level)
3. Internal Schema (Physical Level)
Schemas and Instances
(contd)
1. External Schema (View Level)
The External Schema is the topmost level in the three-schema architecture
and represents how users or applications interact with the database. It is
sometimes referred to as the user view or application view of the data.
Multiple external schemas can be defined, each providing a different
perspective or customized view of the database for different users.
• Each user or group of users can have their own view of the database. For
example, a student may only see their grades, while a professor can view
grades for all students in a course.
• Users do not need access to the entire database. They may only need to
work with a subset of the data. The external schema allows this subset to
be tailored to user needs.
• The external schema is often implemented using database views, which
are virtual tables that don't store data themselves but retrieve data from
the underlying tables.
• By restricting what data different users can see, the external schema
helps protect sensitive information and enforce security policies.
2. Conceptual Schema (Logical Level)
This schema describes what data is stored in the database and how it is
organized, but without dealing with how the data is physically stored.
• The conceptual schema defines the entire structure of the database,
including entities, attributes, relationships, constraints, and data integrity
Schemas and Instances
• (contd)
The conceptual schema is independent of both the external schema
(what users see) and the internal schema (how data is stored). This
separation allows changes to the physical storage of data without
affecting the logical view and vice versa.
• It includes the definition of tables (relations), data types, primary keys,
foreign keys, and other logical constructs that define how data elements
relate to one another.
• The conceptual schema is often modeled using high-level data models
like the Entity-Relationship (ER) model or Relational Model, which
describe the logical organization of the data.
• In the university database:
o The conceptual schema defines the tables such as Students, Courses,
Enrollments, and Grades, along with their attributes like StudentID,
Name, CourseID, Grade, etc.
o It also defines the relationships between these entities (e.g., each
student can enroll in multiple courses, and each course can have
multiple students).
o Constraints like PRIMARY KEY (e.g., StudentID uniquely identifies
3. Internal
eachSchema
student)(Physical
and FOREIGNLevel)
KEY (e.g., StudentID in Enrollments
references
The Internal SchemaStudentID in Students)
is the lowest level ofare
thepart of the conceptual
three-schema schema.
architecture
and represents how data is physically stored in the database.
Schemas and Instances
• (contd)
The internal schema includes details such as how data is organized on
disk, what indexes are used, how data is partitioned or replicated, and
how data blocks are structured.
• The physical level is concerned with optimizing the database for
efficient access and storage. Techniques like indexing, data
compression, and partitioning are implemented at this level.
• The internal schema manages the allocation of data blocks, buffers, and
caching strategies to optimize performance.
• In the university database:
o The Students table might be stored as a set of files on disk using a
particular file format while courses as B-Tree format.
o An index might be created on the StudentID column to speed up
search operations, and the data might be partitioned across
different physical storage devices
Schemas and Instances
(contd)
actual data
Figure 12
1.7
Database Languages and
Interfaces
recap All Actors shall Interact with the
DBMS
2. INSERT Command
The INSERT statement is used to add new records (rows) to a table. This
is a crucial operation in any database system that grows and evolves by
adding new data.
University example:
INSERT INTO Students (Name, Age, Major) VALUES (‘Sunil', 22,
'Computer Science');
3. UPDATE Command
The UPDATE statement is used to modify existing data in a table. This
allows for making changes to records that already exist without deleting
and re-inserting them.
University example:
UPDATE Students SET Major = 'Physics‘ WHERE StudentID = 101;
UPDATE Students SET GPA = 3.9 WHERE Major = 'Computer Science';
Database Languages (contd)
4. DELETE Command
The DELETE statement is used to remove existing records from a table.
It is used when data is no longer needed or has become irrelevant.
University example:
DELETE FROM Students WHERE StudentID = 101;
1. GRANT
The GRANT command is used to provide privileges (permissions) to users or
roles so that they can perform specific operations on the database. These
privileges may include actions such as querying data (SELECT), modifying
data (INSERT, UPDATE, DELETE), or managing the structure of the database
(CREATE, ALTER, DROP).
2. REVOKE Command
The REVOKE command is used to remove previously granted privileges from
users or roles. This command ensures that users no longer have access to
CREATE ROLE ,
perform specific actions on the database or its objects.
SET ROLE, GRANT ROLE,
REVOKE SELECT ON Students FROM Seema ; REVOKE ROLE … etc
Database Languages (contd)
• DCL ensures that only authorized users can access or manipulate specific
data or database objects (e.g., tables, views, functions). The most
commonly controlled objects include: Tables , Views , Indexes , Functions
and Procedures , Schemas etc
• In short , security is one of the main reasons for using DCL commands. It
also help fixing the accountability by carefully controlling who can access
or modify data, organizations can hold users accountable for their actions
5.inTransaction
the database.Control Language ( TCL)
Transaction Control Language (TCL) commands ensure that transactions are
executed in a way that maintains the integrity, consistency, and durability
of the data in the database. It ensure that transactions adhere to the ACID
properties. TCL provide mechanisms for commitment and rollback of
transactions, ensuring that the database remains in a consistent state, even
in the event of an error or system failure. There are four primary TCL
commands:
2. ROLLBACK Command
The ROLLBACK command is used to undo all changes made by the current
transaction. If a problem or error occurs during the transaction, the
ROLLBACK command restores the database to its state before the
transaction began, discarding all the changes made within the transaction.
BEGIN TRANSACTION;
INSERT INTO Students (Name, Age, Major)
VALUES (‘Meera', 23, 'Engineering');
UPDATE Students
SET Major = 'Biology'
WHERE Name = ‘Meera';
Something went wrong or a condition failed, so rollback the transaction !!!!
ROLLBACK; -- Undo all changes made during the transaction
Database Languages (contd)
3. SAVEPOINT Command
The SAVEPOINT command is used to set a checkpoint within a transaction.
You can later roll back the transaction to this specific savepoint , instead of
rolling back the entire transaction. It provides more control over transaction
management by allowing partial rollbacks.
The Interfaces are different for different roles.. For Eg. System Analyst ,
Database Administrators may use graphical tools (GUIs) , Technical users like
Application Programmers may use command-line tools and APIs.
• Simple or Composite
• Single or Multi-valued
• Stored or Derived
• NULL
(a) Simple
A simple attribute cannot be divided
further into smaller parts.
(b) Composite
A composite attribute can be
divided into smaller sub-parts,
each representing more basic
attributes. It can be divided into
smaller subparts, which represent
more basic attributes with
ER Model – Attributes
(contd)
(c) Single-Valued Attribute
A single-valued attribute
holds only one value for
each entity instance.
1. Relationship Degree
2. Cardinality
3. Participation Constraints
1. Relationship Degree
In the Entity-Relationship (ER) Model, the degree of a relationship refers to
the number of entity types that participate in a relationship. It indicates
how many entities are involved in a particular relationship instance.
Accordingly we have :
- Unary relationship
- Binary Relationship
- Ternary Relationship
- Higher degree Relationship
ER Model -
Relationship
entity type. In this case, the relationship involves only one entity type, but
an entity may be related to itself or to other entities of the same type.
Unary relationships are typically used to model hierarchical or recursive
structures, such as an student supervising another student or a part being a
subpart of another part.
2. Cardinality
Cardinality in the context of the Entity-Relationship (ER) Model refers to the
number
of instances of one entity that can or must be associated with each
instance of another entity through a relationship. The following types of
Cardinality are found in a Database Model:
1. One-to-One (1:1)
2. One-to-Many (1:N)
3. Many-to-One (N:1)
4. Many-to-Many (N: N)
Course Enrol
Student
l
Partial Course
Total Students
Addres
Studen s Dist
t .
Roa
d
Strong & Weak Entity
Sets(contd)
Countr Stat
Student Cours y
ID e
e
Addres
Ha Dist
Student s
s
.
Roa
Strea Yea d
m r
Total Participation of E2 in R
Weak Entity
1 N
E1 R E2
Relationship
Cardinality Ratio 1 to Many for E1:E2
in R
N 1
E1 R E2
attribute
Multi value
attribute Cardinality Ratio Many to manyfor E1:E2
in R
ER Diagram : University Course
Registration
https://app.creately.com/d/kMpo3308pPo/edit
ER Diagram : Company
ER Diagram : University Library
( Assignment -1)
Problem statement :
Identify the entities, attributes, and relationships from the given
requirements. Specify the primary keys and foreign keys for each
entity and draw the ER diagram showing the relationships between
the entities. You may enlarge the scenario if you want.
You may consider following scenario :
• Library contains many Books. Book may have some attributes say like
(Book_Id, Title, Category, Author etc ). You can add more that you feel
deemed fit.
• Library members can borrow books. Libraray members may have
attributes like ( Member_Id , Name , email , Membership_Start_Date ,
Membership_Status etc). You can add more that you feel deemed fit.
• Borrowing process can have attributes say (Borrow_Date , Return_Date
etc ). Add more if you feel there can be more attributes.
• Library Staff manages borrowing the book and may have attributes like (
Staf_Id , Position , Hire_Date, email_Id)
• Book can have variety of categories. Please assume as per your will.
ER Diagram : ATM Vending
Machine
Problem statement :
( Assignment -2)
Identify the entities, attributes, and relationships from the given
requirements. Specify the primary keys and foreign keys for each
entity and draw the ER diagram showing the relationships between
the entities. You may enlarge the scenario if you want.
You may consider following scenario :
• The ATM user is the Bank customer. Each customer may have some
attributes say like (Customer_Id, Name, Address, Age etc ).
• The customer shall have a Bank accounts. Each Bank account may have
attributes like ( Account_Id , Account_type, Balance, Account_Status,
etc).
• The ATM machine may have attributes say (ATM_ID , Location ,
Install_Date , Status etc ). Add more if you feel there can be more
attributes.
• The ATM transaction may have attributes like ( Transaction_Id ,
Transaction_Type , Transaction_Amount, Transaction_Date ,
Transaction_Status etc)
• The customer ATM card may have attributes say like ( Card_Number ,
Card_Type , Card_Status etc , PIN , Expiry_Date etc).
ER Diagram : Company database
( Assignment -3 )
Problem statement :
Identify the entities, attributes, and relationships from the given
requirements. Specify the primary keys and foreign keys for each
entity and draw the ER diagram showing the relationships between
the entities. You may enlarge the scenario if you want.
You may consider following scenario :