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

Relational Data Model and SQL: Data Models Relational Database Concepts Introduction To DDL & DML

The document discusses the relational data model and SQL. It provides an overview of data models, including that a data model represents real-world objects and consists of structural, manipulative, and integrity rules. It describes the relational data model, which represents data as tables with rows and columns and uses keys to relate tables. The relational model is implemented in relational database management systems using SQL to define, manipulate, and retrieve data.

Uploaded by

Pius Virt
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Relational Data Model and SQL: Data Models Relational Database Concepts Introduction To DDL & DML

The document discusses the relational data model and SQL. It provides an overview of data models, including that a data model represents real-world objects and consists of structural, manipulative, and integrity rules. It describes the relational data model, which represents data as tables with rows and columns and uses keys to relate tables. The relational model is implemented in relational database management systems using SQL to define, manipulate, and retrieve data.

Uploaded by

Pius Virt
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 49

Relational Data Model and SQL

INTRODUCTION TO DATABASES:
Data models
Relational database concepts
Introduction to DDL & DML
Data Models
2

Underlying the structure of a database is the data


model:
Data model: a collection of conceptual tools for
describing data, data relationships and consistency
constraints.
A model is a representation of ‘real world’ objects
and events, and their associations.

Introduction to Database Languages


Data Models
3

A data model can be comprising of three components:


 A structural part, consisting of a set of rules that
define how the database is to be constructed;
 A manipulative part, defining the types of operations
(transactions) that are allowed on the data (this
includes the operations that are used for updating or
retrieving data and for changing the structure of the
database);
 Possibly a set of integrity rules, which ensures that
the data is accurate.

Introduction to Database Languages


Data Models
4

The purpose of a data model is to represent data and to


make the data understandable.
If it does this, then it can be easily used to design a
database
Provides basic notations and concepts that will allow
database designers and end-users to unambiguously and
accurately communicate their understanding of the
organisational data.
Data modelling allows one to see the options provided by
possible representations and to predict the effects of
decisions.
Introduction to Database Languages
Data Model ...
5
If not done well, serious problems may arise later in the
development process
Purpose: To represent data in an understandable way.
There are different database models which include:
 Relational

 Network and Hierarchical database models.


 ERD: mainly used in design
 Object based: Object oriented and object-relational
 Semi-structured e.g. XML
Introduction to Database Languages
Classes
6

There have been many data models proposed in


the literature.
They fall into three broad categories:
 object-based, record-based, and physical
data models.
The first two are used to describe data at the
conceptual and external levels, the third is used to
describe data at the internal level.

06/22/22
Object-Based Model
7

Object-based data models use concepts such as


entities, attributes, and relationships.
An entity is a distinct object (a person, place,
thing, concept, event) in the organization that is to
be represented in the database.
An attribute is a property that describes some
aspect of the object that we wish to record,
A relationship is an association between entities.

06/22/22
Object-Based Model
8

Some of the more common types of object-based


data model are:
Entity-Relationship (ER)
Semantic
Functional
Object-oriented
The ER model has emerged as one of the main
techniques for database design and forms the basis
for the database design methodology

06/22/22
Object-Based Model
9

The object-oriented data model extends the


definition of an entity to include not only the
attributes that describe the state of the object but
also the actions that are associated with the object,
that is, its behavior
The object is said to encapsulate both state and
behavior

06/22/22
Record-Based Data Models
10

In a record-based model, the database consists of a


number of fixed-format records, possibly of differing types.
Each record type defines a fixed number of fields, typically
of a fixed length
There are three principal types of record-based logical data
model: a
 the relational data model, the network data
model, and the hierarchical data model.

06/22/22
Record-Based Data Models
11

The hierarchical and network data models were


developed almost a decade before the relational
data model,
Their links to traditional file processing concepts
are more evident.

06/22/22
Data models...
12

These fall under one of the following categories of


data models:
 Object-based, Record-based and Physical models

Record-based Data Models


Database consists of a number of fixed-format
records possibly of differing types.
Each record type is defined by a fixed number of
fields, each with a fixed length
These include; Relational, Network and Hierarchical
data models.
Introduction to Database Languages
Examples of Data models cont’d
13

Physical Data Models


Present how data is stored in a computer e.g.
structures of records.
Relational Data Model
 A database structure that treats all of its data as a
collection of relations
 Data and relationships are represented as tables,
each having uniquely identified columns
 Based on mathematical relations

Introduction to Database Languages


Example of a Relational DB
14
• A company needs to store information on departments and
employees.

• Each table contains data that describes exactly one entity - a


thing of significance about which information needs to be
known.
Relational Data Model…
15

note that there is a relationship between Employee and


Department:
 a Department office has Employee.

However, there is no explicit link between these two tables;


It is only by knowing that the attribute depNo in the Employee
relation is the same as the deptNo of the Department relation
that we can establish that a relationship exists.
The model requires only that the database be perceived by the
user as tables.

06/22/22
Relational Database Concepts
16

Relational Database Management Systems (RDBMS)


have become the prevalent means of managing data
RDBMS comprises of software facilitating entry,
storage and data retrieval
Modern RDBMS rely on relational data model to
organize records within
Relational databases: organized in entities, attributes
and tuples
The relational model is based on the mathematical
concept of a relation,
Physically represented as a table.
Introduction to Database Languages
Relational Database Concepts…
1.17

Each table has multiple columns, and each column


has a unique name.
The data is inserted into the table in the form of
tuples – row
Each row in the table represents a collection of
related data values.
It represents a fact that typically corresponds to a
real-world entity or relationship.
A tuple is formed by one or more attributes,
Relational Database Concepts…
1.18

It’s the basic building block in the formation of


various expressions that are used to derive a
meaningful information.
There can be any number of tuples in the table,
All tuples contain fixed and same attributes with
varying values.
The relational model is implemented in database
where a relation is represented by a table,
An attribute is represented by a column of the table,
Relational Database Concepts…
1.19

Attribute name is the name of the column such as;


 ‘identifier’, ‘name’, ‘city’ etc.,
Attribute value contains the value for column in
the row.
The table name and column names help to
interpret the meaning of the values in each row.
Relational Model Terminologies
1.20

Relation – a table composed of rows and columns


Attribute – a column of a relation.
Tuple – a row of a relation.
Cell – an intersection of a row and a column of a
relation.
Domain – a set of allowable/possible values for one
or more attributes.
 Domains are an important feature of the
relational model.
Relational Model Terminologies …
21

 Every attribute in a relational database is


associated with a domain.
Null – a value that is unknown or not applicable in a
given cell.
Degree – number of attributes for a given relation.
Cardinality – number of tuples for a given relation.
Relation schema – a named collection of attributes
and any data constraints.

Introduction to Database Languages


Relational Model Terminologies …
22

Representation of a department relation schema


DEPARTMENT (DeptNo, DName, Loc)
Data Constraints:
 A department name value must never be repeated.

Primary key – attribute(s) that is selected to identify


tuples uniquely within a relation.
 A primary key value must be unique and cannot be
null.
Unique key – attribute(s) that contains distinct values
but can also accommodate null values.
Introduction to Database Languages
Relational Model Terminologies …
23

Foreign key – attribute(s) within one relation that


matches attribute(s) of another or same relation.
A foreign key value must match the
primary/unique key value of some tuple in its
parent relation or the foreign key value must be
wholly null.
Instances of Branch and Staff (part) Relations
24

Introduction to Database Languages


Examples of Attribute Domains
25

Introduction to Database Languages


Alternative Terminologies for Relational
Model
26

Introduction to Database Languages


Relational Database Concepts…
27
A relational database consists of tables that are appropriately
structured.
Representation of a relational database schema for a company
that stores information on departments and employees.

DEPARTMENT (DeptNo, DName, Loc)


EMPLOYEES (EmpNo, EName, Job, Mgr, HireDate,
Sal, Comm, DeptNo)
 Data Constraints://constraints are set rules placed on a
relation

Introduction to Database Languages


Relational Database Concepts…
28

A department name value must never be


repeated.
 No employee should earn a salary that is more
than 5000

Introduction to Database Languages


Properties of Relations:
29

1. Uniqueness of relation names in a relational


database schema.
2. A cell of a relation contains exactly one atomic
(single) value.
3. Each column has a distinct name.
4. Order of attributes / tuples for a given relation is
not significant
5. Values of an attribute are from the same domain.

Introduction to Database Languages


Relational Integrity
30

The first integrity rule applies to the primary keys of base


tables
Entity Integrity
 In a base relation, no attribute of a primary key can be
null. (Please note that this is a correct statement:
because a primary key may be formed of more than
one attribute.)
Referential Integrity
 If foreign key exists in a relation, either foreign key
value must match a primary key value of some tuple
in its home relation or foreign key value must be
wholly null.
Introduction to Database Languages
Database Languages
31

Dedicated programming languages, tailored and


utilized to define a database, manipulate its content and
query it
Database Languages are known as data Sublanguages.
DBMSs have a facility for embedding the sublanguage
in a high-level programming language e.g. C, C++, Java
Or VB.
The high-level language is then known as a host
Language.
Most data sublanguages also provide interactive
commands that can be input directly from a terminal.
Introduction to Database Languages
Database languages...
32

A data sublanguage consists of two parts:


 Datadefinition Language (DDL)
Comprises those instructions used to create, remove
and alter data structures for containing information
 Used to specify the database schema.
 Data Manipulation Language (DML)

Comprises those instructions used for retrieval,


deletion, update & insertion of database contents
 Used to read and update the database.

Introduction to Database Languages


Database languages...
1.33

The data definition and data manipulation


languages are not two separate languages;
They simply form parts of a single database
language, such as;
 the widely used SQL language.
Data Definition Language (DDL)
34

Allows the DBA or user to describe and name the


entities,
 attributes and
relationships
required for the application, together with any
associated integrity and security constraints (Begg &
Connolly, 2002)
DDL is not only used to specify new database
schemas but also to modify exiting ones.

Introduction to Database Languages


Data Definition Language (DDL)…
1.35

A database schema is a logical grouping of objects


that belong to a user.
All created objects / structures (such as tables,
views, indexes) are stored in a database schema.
Relation DB schema objects are created and
maintained by using SQL DDL statements
 (such as CREATE, ALTER, DROP).

The result of compiling DDL statements is a set of


tables stored in special files collectively called the
system catalogue.
DDL ...
36

The system catalogue may also be referred to as a data


dictionary.
The data dictionary integrates the meta-data;
 Definitive information about the structure is recorded in a
data dictionary.
For example:
 definitions about the records, data items and other objects
of interest to users or required by the DBMS.

Introduction to Database Languages


DDL Cont’d
37

The DBMS consults the data dictionary before


accessing or manipulating the data.

Example of DDL SQL statement:


 CREATE, ALTER, DROP, RENAME, TRUNCATE

The following statement in the SQL language defines


the account table:
create table account (account-number char(10),
balance integer)
Introduction to Database Languages
DDL…
38

Execution of the above DDL statement creates the


account table.
In addition, it updates a special set of tables called
the data dictionary or data directory.
A data dictionary contains metadata— data about
data.
The data values stored in the database must satisfy
certain consistency constraints.
DDL…
39

For example, suppose the balance on an account


should not fall below $100.
The DDL provides facilities to specify such
constraints.
 The database systems check these constraints
every time the database is updated.
Data Manipulation Language (DML)
40

Provides a set of operations to support the basic data


manipulation operations on the data held in the
database.

Some of the operations include:


 Insertion of new data into the database
 Modification of data stored in the database

 Retrieval of data contained in the database (Query


language).
 Deletion of data from the database.

Introduction to Database Languages


DML Cont’d
41

There are basically two types:


Procedural DML
 Allows the user to tell the system what data is
needed and how to retrieve the data;
 allows user to tell system exactly how to manipulate
data.
Non-Procedural (Declarative)DML
 allows user to state what data is needed rather than
how it is to be retrieved.
Examples of DML SQL statements;
 INSERT, UPDATE, DELETE and MERGE
Introduction to Database Languages
DML…
42

Declarative DMLs are usually easier to learn and use


than are procedural DMLs.
Since a user does not have to specify how to get the
data,
 the database system has to figure out an efficient
means of accessing data.
The DML component of the SQL language is non-
procedural.
DML…
1.43

The portion of a DML that involves information


retrieval is called a query language.
 A query is a statement requesting the retrieval of
information.
Data Dictionary
44

A data dictionary: a DBMS component that


stores the definition of data characteristics and
relationships.
This “data about data” were labeled metadata.
The DBMS data dictionary provides the DBMS
with its self describing characteristic.
The two main types of data dictionary exist,
integrated and stand alone.
Data Dictionary …
45

An integrated data dictionary is included with the


DBMS
Relational DBMSs include a built in data dictionary
or system catalog
This is frequently accessed and updated by the
RDBMS.
Other DBMSs especially older types, do not have a
built in data dictionary
The DBA may use third party stand alone data
dictionary systems.
Data Dictionary …
46

Data dictionaries can be classified as active or


passive.
 An active data dictionary is automatically
updated by the DBMS
 A passive data dictionary usually requires a
batch process to be run to update it.
The data dictionary stores the description of all
objects that interact with the database.
Information in Data Dictionary
47

There is no standard format for the information


stored in the data dictionary
However, several features are common.
For example, the data dictionary typically stores
descriptions of all:
 Data elements that are defined in all tables of all
databases.
 Specifically the data dictionary stores the name,
datatypes, display formats, internal storage formats,
and validation rules.
Information in Data Dictionary…
48

 It tells where an element is used, by whom it is


used and so on.
 Tables defined in all databases.
 Indexes defined for each database table.
 Defined databases:
 Who created each database, the date of creation,
where it is located and who the DBA is.
 End users and the Administrators of the data base
 Programs that access the database
Information in Data Dictionary…
49

Access authorization for all users of all databases.


Relationships among data elements

Note:
 The users of the database normally don't interact
with the data dictionary,
 It is only handled by the database administrators

You might also like