What is a Database ?
Database
can be defined as a
structured collection of interrelated data that is stored in a
computer. Typically a database is
Shared by multiple applications/users
Independent of application
Reduces redundancy
Database Applications:
Banking: All transactions
Airlines: reservations, schedules
Universities: registration, grades
Sales: customers, products, purchases
Online
Database management
system
A Database management
Advantages of DBMS
In the early days, database applications were
built directly on top of file systems. Advantages
of DBMS over file system include
Minimal data redundancy
Promotes data consistency
Promotes integration of data
Allows concurrent-access of data
Allows enforcement of standards
Ease of application development
Better security
Ensures atomicity of transactions
Levels of Abstraction
Physical level: describes how a record (e.g.,
customer) is stored.
Logical level: describes data stored in database,
and the relationships among the data.
type customer = record
customer_id : string;
customer_name : string;
customer_street : string;
customer_city : integer;
end;
View level: application programs hide details of
data types. Views can also hide information
(such as an employees salary) for security
purposes.
Data independence
Is the separation of data definition from
Data Independence
Logical Data Independence: The
program
Physical schema: database design at the physical
level
Logical schema: database design at the logical
level
Data Models
There are a number of different ways of
Database Models
Conceptual models: logical nature of data
RDBMS
Relational DataBase Management
Systems
collection of tables to
represent both data and
relationship
extensively in relational
database models: relations,
attributes, and domains. A
relation is a table with
columns and rows. The
named columns of the
relation are called attributes,
and the domain is the set of
values the attributes are
allowed to take
Name City
Phone
Smith
192346
Alto
Park 291239
Relational Database
Concept
Dr. E. F. Codd proposed the
relational model for
database
systems in 1970.
It is the basis for the relational
database management
system
(RDBMS).
The relational model consists of
software overhead
Poor design and implementation
Cname
Bookid
phno
address
Bookid
1:M relationship
Storage Management
Storage manager is a program module that
Transaction Management
A transaction is a collection of operations
Query Processing
1. Parsing
and
translation
2.
Optimizati
on
3.
Evaluation
NORMAL FORMS
Normalization
Normalization
is
the
process
of
efficiently
are
two
goals
of
the
normalization
process:
Eliminating Redundant Data
Ensuring Data Dependencies
Reduce
the
amount
of
space
database
ENAME
E001
PRJID
PRJNAME
P001
SQL DVLP
Ashok
P003
ORACLE
DEPT
DEPTNAME
D001
DATABASE
E002
Baskar
P002
.NET
D002
ADV PROG
E004
Catherine
P004
C++
D003
PROG
P005
SYS-ADMIN
P006
SQL DBA
D004
TECH-ADMIN
E005
Domnic
EMP ID
E001
E002
E001
E004
E005
E005
ENAME
Ashok
Baskar
Ashok
Catherine
Domnic
Domnic
PRJID
P001
P002
P003
P004
P005
P006
PRJNAME
SQL DVLP
.NET
ORACLE
C++
SYS-ADMIN
SQL DBA
DEPT
D001
D002
D001
D003
D004
D004
DEPTNAME
DATABASE
ADV PROG
DATABASE
PROG
TECH-ADMIN
TECH-ADMIN
EMP ID
ENAME
PRJID
PRJNAME
DEPT
DEPTNAME
E001
Ashok
P001
SQL DVLP
D001
DATABASE
E002
Baskar
P002
.NET
D002
ADV PROG
E001
Ashok
P003
ORACLE
D001
DATABASE
E003
Catherine
P004
C++
D003
PROG
E004
Domnic
P005
SYS-ADMIN
D004
E004
Domnic
P006
SQL DBA
D004
PRJID
PRJNAME
DEPT
P001
P002
P003
P004
SQL DVLP
.NET
ORACLE
C++
D001
D002
D001
D003
P005
SYS-ADMIN
D004
DEPTNAM
E
DATABASE
ADV PROG
DATABASE
PROG
TECHADMIN
EMP ID
E001
E002
E001
E003
E004
TECHADMIN
TECHADMIN
datas
are
brought
together
and
are
PRJNA
DEPTN
DEPT
EMP ID
ME
AME
SQL
DATABA
D001
E001
DVLP
SE
ADV
.NET
D002
E002
PROG
DATABA
ORACLE D001
E001
SE
C++
D003 PROG E003
SYSTECHD004
E004
ADMIN
ADMIN
SQL
TECHD004
E004
DBA
ADMIN
DEPTID
D001
D002
D003
D004
DEPTNA
ME
DATABAS
E
ADV
PROG
PROG
TECHADMIN
PRJID
PRJNAME
EMP ID
P001
SQL DVLP
E001
P002
.NET
E002
P003
ORACLE
E001
P004
C++
E003
P005
SYS-ADMIN
E004
P006
SQL DBA
E004
EMP ENAM
DEPT
ID
E
EMP ID
ENAME
E001
Ashok
E002
Baskar
E003
Catherine
E004
Domnic
Cather
D003
ine
Domni
E004
D004
c
E003
ENAME
DEPT
CITY
CITYCD
E001
Ashok
D001
CHENNAI
Ashok
C001
E002
Baskar
D002
MUMBAI
Baskar
C002
E003
Catherine
D003
CHENNAI
Catherine
C001
E004
Domnic
D004
KOLKATA
Domnic
C003
EMP ID
ENAME
DEPT
CITYCD
E001
Ashok
D001
C001
Ashok
E002
Baskar
D002
C002
Baskar
E003
Catherine
D003
C001
Catherine
E004
Domnic
D004
C003
Domnic
CITY
CITYCD
CHENNAI
C001
MUMBAI
C002
KOLKATA
C003
dirty
What is Denormalization?
Prod_ID
1001
Products
ProdNam
UnitPrice
e
ABCD
10
1002
EFGH
13
1003
IJKL
12
Sales_Order
Prod_id Qty
1001
23
1002
21
1003
4
Sales_Prof
Profit_Pc
1004
MNOP
15
Prod_id
tg
Select p.Prod_id, ProdName, UnitPrice * Qty *
1001
1.34
Profit_Pctg
1002
1.45
Total Price From Products p JOIN Sales_Order s 1003
1.56
ON p.Prod_id = s.Prod_id
JOIN Sales_Prof sp ON p.Prod_id = s.Prod_id
I need to Join Multiple tables to get a total price of the
product, which may take a long time.
What is Denormalization?
Product_Details
Prod_ID
ProdNam UnitPric
e
e
Qty
Profit_Pct
g
1001
ABCD
10
23
1.34
1002
EFGH
13
21
1.45
1003
IJKL
12
1.56
1004
MNOP
15
(NULL)
1.23
ACID PROPERTY
ATOMICITY
Atomicity requires that each transaction is "all or nothing": if one part of the
transaction fails, the entire transaction fails, and the database state is left
unchanged. An atomic system must guarantee atomicity in each and every situation,
including power failures, errors, and crashes.
CONSISTENCY
The consistency property ensures that any transaction will bring the database from
one valid state to another. Any data written to the database must be valid according
to all defined rules, including but not limited to constraints, cascades, triggers, and
any combination thereof.
ISOLATION
The isolation property ensures that the concurrent execution of transactions results in
a system state that could have been obtained if transactions are executed serially,
i.e. one after the other.
DURABILITY
Durability means that once a transaction has been committed, it will remain so, even
in the event of power loss, crashes, or errors. In a relational database, for instance,
once a group of SQL statements execute, the results need to be stored permanently
(even if the database crashes immediately thereafter).
ENTITY-RELATIONSHIP
DIAGRAMS
(ER-DIAGRAMS)
ELEMENTS IN ER DIAGRAMS
Entity
Entities are the principal data
Entity Type
Number
Topic
Course
Entity
Number: 3C13
Name: Database and Information Management Systems
Topic:
Attributes
Attributes
Simple
Professor
Start Date
First
Composite
Professor
Name
Last
Attributes
Single
Multi-Valued
Professor
Employee ID#
Professor
Attributes
Stored
Professor
Start Date
Derived
Professor
Years Teaching
Primary Keys
Professor
Employee ID
in question
Relationships
A Relationship represents an association
Relationships
Professor
teaches
Course
Weak entity
Weak entities do not have key attributes of
their own.
Weak entities cannot exist without another
a relationship to another entity.
A partial key is the portion of the key that
comes from the weak entity. The rest of the
key comes from the other entity in the
relationship.
Weak entities always have total
participation as they cannot exist without
the identifying relationship.
Identifying Relationship
Payment
Made for
Loan
Loan-No
Sample problem:
Design an E-R schema for a database to store info about
professors, courses and course sections indicating the
following:
The name and employee ID number of each professor
The salary and email address (es) for each professor
How long each professor has been at the university
The course sections each professor teaches
The name, number and topic for each course offered
The section and room number for each course section
Each course section must have only one professor
Each course can have multiple sections
Solution:
Employee ID
Start Date
Years Teaching
Professor
teaches
Section
ID
N
Room
Section
N
Salar
y
First
Part of
Name
Last
Number
Course
Topic
Name
SQL
{STRUCTURED QUERY
LANGUAGE }
SQL QUERYING
SQL Commands are used to extract or
65
visit: www.digiterati.com
DDL STATEMENTS
CREATE
ALTER
DROP
CREATE QUERY
SYNTAX:
USER
CREATE
DEFINED
TABLE
<TABLE-NAME>
( <COL-1 > <DATA-TYPE> <CONSTRAINTS>
.
<COL-N> <DATA-TYPE> <CONSTARINTS>
)
CREATE QUERY
EXAMPLE:
CREATE
TABLE
hire_dates
(id NUMBER(8),
hire_date DATE
SYSDATE);
DEFAULT
RESULT:
ALTER QUERY
SYNTAX
DROP QUERY
SYNTAX
DROP
TABLE
<TABLE-NAME>;
THE TABLE .
THE DROPs CAN BE PERFORMED ON
VIEWS & TRIGGERS TOO.
TRUNCATE QUERY
SYNTAX
TRUNCATE
TABLE
<TABLE-NAME>;
DML STATEMENTS
SELECT
INSERT
UPDATE
DELETE
SELECT QUERY
SYNTAX:
SELECT *
FROM <TABLE-NAME>;
SELECT QUERY
EX-1:
SELECT *
FROM
employees;
EX-2:
SELECT employee_id, last_name, job_id, department_id
FROM
employees
EX-3:
SELECT employee_id, last_name, job_id, department_id
FROM
employees
WHERE department_id = 90 ;
INSERT QUERY
SYNTAX:
1 rows inserted
UPDATE QUERY
SYNTAX:
UPDATE table
SET
column = value [, column = value, ...]
[WHERE condition];
EXAMPLE:
UPDATE employees
SET
department_id = 70
WHERE employee_id = 113;
RESULT:
1 rows updated
DELETE QUERY
SYNTAX:
1 rows deleted
DCL STATEMENTS
GRANT
REVOKE
GRANT STATEMENT
GRANT : gives user rights and privileges on
GRANT privilege_name
ON
object_name
TO
{user_name |PUBLIC |role_name}
[WITH GRANT OPTION];
REVOKE STATEMENT
REVOKE : removes or restricts user rights
REVOKE privilege_name
ON
object_name
FROM
{user_name |PUBLIC |role_name}
PRIVELAGES
Privileges: Privileges defines the access
TCL STATEMENTS
COMMIT
ROLLBACK
SAVEPOINT
changes permanent
Group logically related operations
TCL - OPERATIONS
database.
The previous state of the data is
permanently lost.
All users can view the results.
Locks on the affected rows are released;
those rows are available for other users to
manipulate.
All savepoints are erased.
SUMMARY
DATABASE
DBMS
RDBMS
E-R DIAGRAMS
SQL-[STRUCTURED QUERY LANGUAGE ]
QUERIES
THANK
YOU