DataBase System CH - 1-5
DataBase System CH - 1-5
Introduction
Data: a collection of raw and unorganized facts or individual facts
include:- prices, weights, addresses, ages, names, temperatures, dates,
or distances.
Data can be simple—and may even seem useless until it is analyzed,
organized, and interpreted.
Information: processed data in a form that is meaningful to the user.
information is the result of analyzing and interpreting pieces of data.
Information System is a system that:
Receives data and instruction.
Processes the data as per the instruction.
Produces output.
Stores data/information for future use.
Database System 1
Introduction to Database
Traditional way of data/information handling where cards and paper
are used for the purpose. Typing the data on paper and put in a file
cabinet. The data storage and retrieval will be performed using human
labour
Database System 2
Con’t..
Play a critical role in almost all areas where computers are used,
including Business, Engineering, Medicine, Law, Education, And
Library Science, Etc.
Database System 5
Database
The cost and risk during conversion from the old to the new system
is high.
Database System 10
Con’t..
Database System 11
Database Management System(DBMS)
Is a collection of programs that enables users to create and
maintain a database.
Defining database
Constructing database
DBMS.
Database System 13
Components of DBMS Environment
maintain databases.
These facilities will help the designer, the user as well as the
Database System 14
Con’t…
constraints
Database System 15
Con’t…
database.
data model
Database System 16
Con’t…
Since the required data or Query by the user will be extracted using
Database System 18
Types Of Database Model
A model is a representation of real world objects and events and their
associations. Data model can be divided into four:
Hierarchical database model: Consists of an ordered set of
trees in a parent child mode.
Connection between child and its parent is called a Link.
1-1 or 1-M link is allowed.
It is inflexible
Used widely in applications like bank, tecom etc.
Easy to understood
Top down ways of viewing business entity
Allows a node to have only one parent.
Database System 19
Con’t..
Network model: is the extension of the hierarchical structure
because it allows many-to-many relationships to be managed in a
the case of hierarchical model, here a node can have any number
of parents.
attributes.
model
Database System 21
Stages of data model
It is highly abstract.
Easily understood
Take_Cour
Only entities are visible se
Abstract R/ship
Database System 21
Cont..
Database System 22
Steps In Requirements Analysis for Database
Identify scope of the design effort.
Establish metadata collection standards - who to interview, what to
collect - how to structure interview.
Identify user views – extracted by reviewing user tasks, types of
decisions. Forms, reports, graphs, maps can be useful information
for defining views. User view- subset of data used by a user in a
specific context
Build a data dictionary - define and describe each item in detail:
name, description, type, length, range and relationships
Identify data volumes and usage patterns how much data is used
and how frequently is data change.
Identify operational (functional) requirements..
Database System 23
Con’t..
Database System 25
Individual Assignment One (5%)
Database System
Chapter two
Conceptual level data design: Refers to the Entity-Relationship (E/R) Data Model.
Entity - Relationship (E/R) : Views the real world as a set of basic objects (entities)
and relationships among these objects.
Eg “EMPLOYEES”(EMPLOYEE1, EMPLOYEE2,
EMPLOYEE3,etc ) entity set represents all the set of
employees
DEPENDAN
EMPLOYEE
T
Addre
Salary
ss
Identifiers or
Descriptors.
Eg EMPLOYEE
Mang DEPARTMENT
es
Line- for the link b/n the attributes & the entity sets and
Arrow Head Line- for the link b/n an entity set & a one-
to-one r/ship
Alternate key: All the keys which are not primary keys are called
alternate keys.
Types of constraints
NOT NULL
UNIQUE
DEFAULT
CHECK
Key Constraints – PRIMARY KEY, FOREIGN KEY
Mapping constraints
Domain constraints
Database System 2-29
Cont..
NOT NULL: constraint makes sure that a column does not hold NULL
value. When we don’t provide value for a particular column while
inserting a record into a table, it takes NULL value by default.
Key constraints:
Mapping Cardinality:
Integrity means the set of rules and regulations to restrict the kind
of attributes or values a column or relation can hold in the database
table.
Find the maximum number of super keys and the total number of
super keys using the following student table.
Database System
Chapter three
Relational database design:
Relational database design (RDD) use tables to store information.
The standard fields and records are represented as columns (fields/
attributes) and rows (records/ tuple) in a table.
The above table is not normalized. We will see the problems that we
face when a table is not normalized.
non-prime attribute.
attributes.
♦ Now XY is the creation of PD.
Example 2:- based on slide number 7 convert into 2NF( not in 2NF)
Conversion to 2NF
A → B:
A is a super key
NPA PA (create a problme )
3. What is ODL? Explain with a neat diagram and compare with ER.
Database System
Chapter four
Database System
Relational algebra
Relational Algebra is a procedural query language that consists of a
set of operations that take one or two relations as input and produce a
new relation as a result. The algebra operations enable a user to
retrieve specific requests on a relational model
Unary Operators .
Selection (σ)
Projection (Π)
Rename(ρ)
Binary Operators .
Union (U )
Intersection (˄)
Difference ( – )
The binary operators listed above are also known as set operators.
Unary Operations:
OR
After the renaming the name of the relation and the attributes can be
used as ordinary relation and attributes in a sequence of relational
algebra expressions:
EmpTeams(EmpId, TeamId)
Two relations R(A1, A2, … An) and S(B1, B2, … Bn) are said to be
union compatible if
Find the name and position of Employees that work on both Projects 1
and 2 as Programmers. It is Similar to the previous example.
EmpTeams(EmpId, TeamId)
Theta Join Operation: While the natural join enforces a join condition
by equating similar attributes in the relations to be joined; a theta join
joins relations to an arbitrary condition C.
Outer Join
Extended Projection
Duplicate Elimination
However, there are cases when we want to have all the tuples from the
participating relations and form the join when there is much. In such
cases, outer join operations can be used to keep all the tuples in R, or
all those in S, or all those in both relations irrespective of their having
matching tuples in their common attributes.
Left Outer Join: Keeps every tuples in the left relation R and when
there is no matching for tuples in R from tuples in S, the attributes
of S are filled (padded) with NULL values.
It is denoted by:
It is denoted by:
It is denoted by:
Find the loan number for each loan of an amount greater or equal to
10,000.
Find the names of all customers having a loan at the “ABC” branch.
Formulas in the predicate are build in the same ways as the tuple
calculus predicates.
Database System
Structured query language(SQL)
What is SQL? SQL stands for Structured Query Language
Table – Relation
Column – Attribute
Row – Tuple
user
Datatypes:- is the SQL supported data types: char, varchar, int, small
int, decimal, date, time(date time),……
Example: create table parent ( pid int not null primary key ,Pname
char(20) not null, age int )
create table child ( cid int not null primary key, pid int foreign key
references parent(pid) on delete cascade on update cascade
Here, column1, column2, ... are the field names of the table you want
to select data from.
If you want to select all the fields available in the table, use the
following syntax: Select * from table_Name
Eg:
SELECT column_name(s)FROM table_nameWHERE condi
Database System 5-16
Cont..
The WHERE clause it is a search condition used to filter records.
The WHERE clause is used to extract only those records that fulfill a
specified condition.
Aliases are often used to make column names more readable and to
avoid ambiguity .
To remove duplicates and have a set of rows as a result one can the
DISTINCT key word on the SELECT clause as follows
There are two wildcards often used in conjunction with the LIKE
operator:
% The percent sign represents zero, one, or multiple characters
_ The underscore represents a single character
The ANY and ALL operators are used with a WHERE or HAVING
clause.
The ANY operator returns true if any of the sub query values meet
the condition.
SELECT column_name(s) FROM table_name
WHERE column_name
operator ANY(SELECT column_name FROM table_name WHE
RE condition);
Eg: SELECT ProductName FROM Products
WHERE ProductID= ANY (SELECT ProductID FROM
OrderDetails WHERE Quantity = 10);
Database System 5-26
Cont..
The ALL operator returns true if all of the sub query values meet
the condition.
The EXISTS operator returns true if the sub query returns one or more
records.
EXISTS Syntax: SELECT column_name(s) FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE condition);
The BETWEEN operator: selects values within a given range. The
values can be numbers, text, or dates. It is inclusive: begin and end
values are included.
Syntax: SELECT column_name(s) FROM table_name
WHERE column_name BETWEEN value1 AND value2;
types of join:-
The query returns all the projects, and if the projects are having teams
the teams will be joined with the teams as well. Projects having more
than one team will be joined with each teams in the resulting table.
Syntax:
SELECT column1, column2, ...FROM table_name
ORDER BY column1, column2, ... ASC|DESC;
WHERE applies to data read from tables, and HAVING should only
apply to aggregated data, which isn't known in the initial stage of a
query Database System 5-40
views
In SQL, a view is a virtual table based on the result-set of an SQL
statement.
A view contains rows and columns, just like a real table. The fields in
a view are fields from one or more real tables in the database.
You can add SQL functions, WHERE, and JOIN statements to a view
and present the data as if the data were coming from one single table.