Basic RDBMS Concepts
-
Upload
kingshuk-srivastava -
Category
Documents
-
view
221 -
download
0
Transcript of Basic RDBMS Concepts
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 1/62
RDBMS Concepts
BY
KINGSHUK SRIVASTAVA
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 2/62
Agenda
Introduction
Database Management Systems
Normalization
Codd’s Rules SQL
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 3/62
Introduction
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 4/62
Why Study Databases??
Shift from computation to information
always true for corporate computing
Web made this point for personal computing
more and more true for scientific computing
Need for DBMS has exploded in the last years Corporate: retail swipe/clickstreams, “customer
relationship mgmt”, “supply chain mgmt”, “data
warehouses”, etc.
Scientific: digital libraries, Human Genome
project, NASA Mission to Planet Earth, physicalsensors, grid physics network
DBMS encompasses much of CS in a practical
discipline
OS, languages, theory, AI, multimedia, logic
Yet traditional focus on real-world apps
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 5/62
What’s the intellectual content?
representing information data modeling
languages and systems for querying data
complex queries with real semantics*
over massive data sets concurrency control for data manipulation
controlling concurrent access ensuring transactional semantics
reliable data storage maintain data semantics even if you pull the
plug
* semantics: the meaning or relationship of meanings of a sign or set of signs
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 6/62
Data?
Information?
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 7/62
Initial Data Storage Methods
Data is represented in one or more flat files
Flat file is nothing but electronic representation of cardboard file.
Every business group has its own set of files
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 8/62
Disadvantages of Flat File Systems
No centralized control.
Data Redundancy
Data Inconsistency
Data can not be shared
Standards can not be enforced
Security issues
Integrity can not be maintained Data dependence
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 9/62
Database Management Systems
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 10/62
Database Management Systems
A system whose overall purpose is to record andmaintain information
A database is a repository for stored data andprograms to manipulate it.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 11/62
Advantages of DBMS
Centralized control.
No Data Redundancy
Data Consistency
Data can be shared
Standards can be enforced
Security can be enforced
Integrity can be maintained Data independence
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 12/62
Data Models
A data model is a collection of concepts fordescribing data
A Schema is a description of a particular collection of
data using the given data model The relational model is the most widely used model
today
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 13/62
Levels of Abstraction
Many Views and single Conceptualand Physical Schema• Views Describe how users see the data
•Conceptual Schema defines the logicalstructure•Physical Schema defines the physicalfiles and Indexes
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 14/62
Example University Database
Conceptual Schema Students(sid: string, name: string, login: string, age:
integer, gpa:real)
Courses(cid: string, cname:string, credits:integer)
Physical Schema Relations stored as unordered files.
Index on first column of Students.
External Schema (View): Course_info(cid:string,enrollment:integer)
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 15/62
Data Independence
Applications insulated from how data is structuredand stored
Logical Data Independence: Protection from changesin logical structure of data
Physical Data Independence: Protection from
changes in physical structure of data
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 16/62
Structure of a DBMS
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 17/62
ACID Test
Atomicity
Consistency
Isolation
Durability
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 18/62
Transactions: ACID Properties
Key concept is a transaction: a sequence of database actions(reads/writes).
DBMS ensures atomicity (all-or-nothing property) even if systemcrashes in the middle of a Xact.
Each transaction, executed completely, must take the DB betweenconsistent states or must not run at all.
DBMS ensures that concurrent transactions appear to run in isolation.
DBMS ensures durability of committed Xacts even if system crashes.
Note: can specify simple integrity constraints on the data. The DBMSenforces these.
Beyond this, the DBMS does not understand the semantics of thedata.
Ensuring that a single transaction (run alone) preserves consistency is largely the user’s responsibility!
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 19/62
Types of DBMS
Hierarchical
Network
Relational
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 20/62
Hierarchical DBMS (Contd.)
Can not handle Many-Many relations
Can not reflect all real life situations
Anomalies in insert, delete and update operations.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 21/62
Network DBMS
Data is represented by records and pointers
Addresses Many-Many relations
Insert,delete,update operations possible
Complex in design
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 22/62
Relational DBMS
Based on Relational Mathematics principles
Data is represented in terms of rows and columns of a table
Addresses all types of relations Easy to design
No anomalies for insert/delete/update
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 23/62
Relational Terminology
Tuple (Row) Attribute (Column)Relation (Table)
Integrity ConstraintsPrimary Key Alternate Key Foreign Key
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 24/62
Normalization
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 25/62
Normalization
Normalization - process of removing dataredundancy by decomposing relations in a Database.
De normalization - carefully introduced redundancy to improve query performance.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 26/62
Normalization through decomposition
The decomposition approach starts with one relationand the relation is decomposed into more number of relations to remove insert, delete and updateanomalies.
1NF, 2NF, 3NF and BCNF can be achieved by thisapproach.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 27/62
Un normalized Form
A relation is said to be in Un normalized Form (0NF)if the values of any of its attributes are non-atomic.In other words more than one value is associated
with each instance of the attribute.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 28/62
Un normalized Relation
PQS#
P# QTY
S1 P1P2
P3
P4
300200
400
200
S2 P1
P2
300
400
S3 P2 200
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 29/62
First Normal Form
A Relation is said to be in First Normal Form (1 NF) if the values of each attribute of the relation areatomic. In other words, only one value is associated
with each attribute and the value is not a set or a listof values.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 30/62
Functional Dependency
Given a relation R, attribute Y of R is functionallydependent on attribute X if and only if each X-valuein R has associated with it precisely one Y-value in R (at any one time)
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 31/62
Full Functional Dependency
Attribute Y is fully functionally dependent on attributeX if it is functionally dependent on X AndFunctionally dependent on any proper subset of X
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 32/62
Second Normal Form
A relation R is in Second Normal Form (2 NF) if it is inthe 1NF and every non key attribute is fullfunctionally dependent on the primary key.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 33/62
Third Normal Form
A relation R is in Third Normal Form (3 NF) if andonly if it is in the 2NF and every non-key attribute isnon-transitively dependent on the primary key.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 34/62
Boyce Codd Normal Form
A relation R is in Boyce/Codd Normal Form (BCNF) if and only if every determinant is a candidate key.
An attribute, possibly composite, on which some otherattribute is fully functionally dependent is adeterminant .
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 35/62
A subject can be taught to a student by only oneteacher.
Each teacher teaches only one subject.
Each subject is taught by several teachers.
Student Subject TeacherSmith Maths Prof. WhiteSmith Physics Prof. GreenJones Maths Prof. WhiteJones Physics Prof. Brown
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 36/62
No two students can get same position in samesubject.
Student Subject PositionSmith Maths 1Smith Physics 2Jones Maths 2
Jones Physics 1
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 37/62
Codd’s Rules
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 38/62
Codd’s Rules
• 1985
• Proposed to test DBMSs for confirmation to concept of Codd’s Relational model
• Hardly any commercial product follows all
• Oracle = 81 2 out of 12.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 39/62
Rule Zero
• For a system to qualify as an RDBMS it must be able to manage its databases entirely through its Relationalcapabilities
• The other 12 rules derive from this rule
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 40/62
Rule 1: Information Rule
• All Information (inlcuding metadata) is to berepresented as data stored in cells of tables.
• The rows and columns have to be strictly unordered.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 41/62
Rule 2: Guaranteed Access
• Each unique piece of data (atomic value) should be accesible by : TableName + Primary Key (Row) +
Attribute (Column)
• Violation: Ability to directly access via pointers
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 42/62
Rule3: Systematic treatment of NULL
• NULLs may mean: Missing data, Not applicable, No
value
• Should be handled consistently - Not Zero or Blank
• Primary keys — Not NULL
• expressions on NULL should give NULL
◭◭ ◮◮
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 43/62
Rule4: Active On-Line Catalogue
• Database dictionary (Catalogue) to have description of the Database
• Catalogue to be governed by same rules as rest of the database
• The same query language to be used on catalogue as on the application database
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 44/62
Rule5: Powerful language
• One well defined language to provide all manners of access to data
• Example: SQL
• If file supporting table can be accessed by any manner except a SQL Interface, then a violation
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 45/62
Rule6: View Updating Rule
• All views that are theoretically updatable should be
updatable
• View = "Virtual table", temporarily derived from base tables
• Example: If a view is formed as join of 3 tables, changes to view should be reflected in base tables
• Not updatable: View does not have NOT-NULL at-
tribute of base table
• Problems with computed fields in view e.g. Total Income = White income + Black income
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 46/62
Rule7: Relational level operations-
• There must be insert, update, delete operations at the
level of Relations
• Set operations like Union,Intersection and Minus
should be supported
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 47/62
Rule8: Physical Data Independence
• The physical storage of data should not matter to the
system
• If say, some file supporting table was renamed or moved from one disk to another, it should not effect the applications.
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 48/62
Rule9: Logical Data Independence
• If there is change in the logical structure (table struc-
tures) of the database the user view of the data should
not change
• implemented through views. Say, if a table is split into
two tables, a new view should give result as the join
of the two tables
• Difficult rule to satisfy
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 49/62
Rule10: Integrity Independence
• The database should be able to enforce its own integrity rather than using other programs
• Integrity rules = Filter to allow correct data, should
be stored in Data Dictionary
• Key and check constraints, triggers etc should be
stored in Data Dictionary• This also makes RDBMS independent of front end
R l 11 Di t ib ti I d d
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 50/62
Rule11: Distribution Independence
• A database should work properly regardless of its distributionacross a network
• This lays foundation of Distributed databases
• Similar to Rule8 only that applies to distribution on
a local Disk
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 51/62
Rule12: Non-subversion Rule
• If low level access is allowed to a system it should not be able to subvert or bypass integrity rules to change
data
• This may be achieved by some sort of locking or encryption
• Some low level access tools are provided by vendors that violate these rules for extra speed
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 52/62
Structured Query Language
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 53/62
Structured Query Language
DDL – Data Definition Language
DML – Data Manipulation language
DCL – Data Control Language
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 54/62
DDL
Create
Alter
Drop
Truncate
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 55/62
DML
Insert
Update
Delete
Select
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 56/62
DCL
Commit
Rollback
Save point
Set transaction
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 57/62
Integrity Constraints
Primary key (PK)
Foreign Key (FK)
Unique key (UK)
Not Null Check
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 58/62
Data Types
Character
Varchar2
Number
Date BLOB
BFILE
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 59/62
Arithmetic Operator
+
-
*
/ Mod
ABS
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 60/62
AND OR IN NOT IN < > <= >= <> BETWEEN
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 61/62
Set Operators
UNION UNION ALL
INTERSECTION
MINUS
8/4/2019 Basic RDBMS Concepts
http://slidepdf.com/reader/full/basic-rdbms-concepts 62/62
Thank You