6/25/20151 introduction to database systems zpurpose of database systems zviews of data zdata models...
Post on 21-Dec-2015
228 views
TRANSCRIPT
04/18/23 1
Introduction to Database Systems
Purpose of Database Systems Views of Data Data Models Data Definition Language Data Manipulation Language Transaction Management Storage Management Database Administrator Database Users Overall System Structure
04/18/23 2
Database Management System (DBMS)
Collection of interrelated dataSet of programs to access the dataDBMS contains information about a
particular enterpriseDBMS provides an environment that
is both convenient and efficient to use.
04/18/23 3
Purpose of Database Systems
Difficulties in conventional file-processing systems: (DBMS attempts to solve) Data redundancy and inconsistency Difficulty in accessing data Data isolation -- multiple files and formats Integrity problems Atomicity of updates Concurrent access by multiple users Security problems
04/18/23 4
View of Data
…...
View level
View 1 View 2 View n
Logical level
Physical level
04/18/23 5
Levels of Abstraction
Physical level: describes how a record (eg.: customer) is stored in terms of block#, sector#, byte# etc.
Logical level: describes data stored in database, and the relationship among the data:
customer { string name; string street; integer city; } View level: Application programs/GUI etc hide the actual
representation and present only the required data in a convenient way. Eg: Visual forms, graphical forms.
04/18/23 6
Instances and Schemas
Schema is a description and an instance is a set of data that fits the description.
Schema : logical structure of the database (eg. Set of customers and accounts and the relationship between them)
Instance : actual content of the database at a particular point in time.
One schema may have many instances.Analogy : type and variable in a programming
language.
04/18/23 7
Data Independence
Ability to modify a schema definition in one level without affecting a scheme definition in the next higher level.
Interfaces between the various levels and components should be well defined so that changes in some parts do not seriously influence others:
Two levels of data independence: Physical data independence Logical data independence
04/18/23 8
Data Models A collection of representations for describing:
data, data relationships, data semantics, data constraints Object-based logical models
Entity-Relationship (ER) model Object-oriented model Semantic model Functional model
Record-based logical models Relational model (e.g. SQL/DS, DB2) Network model Hierarchical Model Object relational model
04/18/23 9
Entity-Relationship Model
customer
name
SSN street
city
account
number balance
depositor
entity
attribute
relationship
04/18/23 10
Relational Model
Name SSN street city account no.
Johnson 192-83-7465 Alma Palo Alto A-101
Customer Table
Account No. Balance
Account Table
A-101 500
04/18/23 11
Data Definition Language (DDL)
Specification notation for defining database scheme
DDL compiler generates a set of tables in a data dictionary
Data dictionary contains metadata (data about data)
Data storage and definition language - special type of DDL in which storage and access methods used by the dbms are specified.
SQL create, define tables
04/18/23 12
Data Manipulation LanguageLanguage for accessing and manipulating
the data organized by appropriate data model
Two classes of languages: Procedural - user specifies what data is required
and how to get those data Non-procedural -- user specifies what data is
required without specifying how to get those dataQuery language (sequential query language:
sql) : insert data, update data
Relational Algebra
Tables representing relationsRow uniquely identified by a primary keyRelated tables are associated using
foreign keysSpecial operators are defined and
axioms: join, project etc.: relational algebra
http://db.grussell.org/section010.html
04/18/23 13
04/18/23 14
Transaction Management
A transaction is a collection of operations that perform a single logical function in a database application
Example: Withdraw $100 from Acct Number A-101 Verify the balance Update account table (& other tables) Deliver money
04/18/23 15
Transaction Management (contd.)
Transaction-management component ensures that the db remains in a correct state despite system failures (e.g. power failures and operating system crashes) and transaction failures.
ACID property: Atomicity, Consistency, Isolation, Durability
Concurrency-control manager controls the interaction among the concurrent transactions.
04/18/23 16
Storage Management
A storage manager provides the interface between the low-level data and the application programs and queries submitted to the system.
The storage manager is responsible for the following tasks: interaction with file-manager efficient storing, retrieving, and updating of
data
04/18/23 17
Overall System ModelNaïve users Application
programmersSophisticatedusers
DBA
Applicationinterfaces
Application programs
query Database scheme
Qu
ery
pro
cess
ing
DBMS System
Object codeEmbeddedDML compiler
DML compiler
DDL interpreter
Query evaluationengine
Sto
rage
man
ager
Transactionmanager
Buffer manager
File manager
Data dictionaryStatistical dataindicesData files
Disk storage
04/18/23 18
Database Administrator
Coordinates all the activities of the database system; DBA should have a good understanding of the
enterprise’s information resources and needs. DBA’s duties include:
Scheme definition Storage structure and access method definition Granting user authority to access the database Specifying integrity constraints Acting as liaison with users Monitoring performance and responding to changes in
requirements
04/18/23 19
Database Users
Differentiated by the how they interact with the system
Naïve users: invoke pre-determined application with high-level user interface
Application programmers; Use DML calls, embedded calls
Sophisticated users: managers, decision support systems: request using query languages
Specialized users: design and write specialized applications.
Links/support
https://wiki.cse.buffalo.edu/services/content/how-use-jdbc-oracle
04/18/23 20
04/18/23 B.Ramamurthy 21
Simple Database ApplicationAPPLICATION
DBMS DB
Ex: AccessOracleMySql
04/18/23 B.Ramamurthy 22
Multi-Databases
APPLICATION
DBMS 1
DBMS 2
DBMS 3
DB
DB
DB
04/18/23 B.Ramamurthy 23
Standard Access to DBAPPLICATION
DRIVER
MGR
DBMSDriver 1
DBMSDriver 2
DBMSDriver 3
DBMS 1
DBMS 2
DBMS 3
DB
DB
DB
04/18/23 B.Ramamurthy 24
ODBC Architecture
Application
Class1 Class2
Driver Manager
DriverType1 DriverType2 DriverType3
DataSource2DataSource1DataSource3
ODBC
04/18/23 B.Ramamurthy 25
Open Database Connectivity (ODBC) Standard
ODBC standard is an interface by which application programs can access and process SQL databases in a DBMS-independent manner. It contains:
A Data Source that is the database, its associated DBMS, operating system and network platform
A DBMS Driver that is supplied by the DBMS vendor or independent software companies
A Driver Manager that is supplied by the vendor of the O/S platform where the application is running
04/18/23 B.Ramamurthy 26
ODBC Interface
It is a system independent interface to database environment that requires an ODBC driver to be provided for each database system from which you want to manipulate data.
The database driver bridges the differences between your underlying system calls and the ODBC interface functionality.
04/18/23 B.Ramamurthy 27
An Example
Application DriverManager
DB2 driver MYSQL driver Oracle driver
odbc standard
API
04/18/23 B.Ramamurthy 28
Application in Java
Application inJava DriverManager
Access driver MYSQL driver Oracle driver
odbc standard
API
jdbc API
04/18/23 B.Ramamurthy 29
Java Support for ODBC : JDBC
When applications written in Java want to access data sources, they use classes and associated methods provided by Java DBC (JDBC) API.
JDBC is specified an an “interface”. An interface in Java can have many
“implementations”.So it provides a convenient way to realize
many “drivers”
04/18/23 B.Ramamurthy 30
Java Support for SQL
Java supports embedded SQL.Also it provides an JDBC API as a standard
way to connect to common relational databases.
You need a JDBC:ODBC bridge for using the embedded SQL in Java.
Java.sql package and an extensive exception hierarchy.
We will examine incorporating this bridge using sample code.
04/18/23 B.Ramamurthy 31
Data Source
Local relational database; Ex: OracleRemote relational database on a
server; Ex: SQLserverOn-line information service; Ex: Dow
Jones, Customer database
04/18/23 B.Ramamurthy 32
Data Source and Driver
Data source is the data base created using any of the common database applications available.
Your system should have the driver for the database you will be using.
For example your Windows system should have the MS Access Driver.
There are a number of JDBC drivers available. On the IDE you are using you will install the
appropriate driver.
04/18/23 B.Ramamurthy 33
JDBC Components Driver Manager: Loads database drivers, and
manages the connection between application & driver. Driver: Translates API calls to operations for a specific
data source. Connection: A session between an application and a
driver. Statement: A SQL statement to perform a query or an
update operation. Metadata: Information about the returned data, driver
and the database. Result Set : Logical set of columns and rows returned
by executing a statement.
04/18/23 B.Ramamurthy 34
JDBC Classes
Java supports DB facilities by providing classes and interfaces for its components
DriverManager classConnection interface (abstract class)Statement interface (to be
instantiated with values from the actual SQL statement)
ResultSet interface
04/18/23 B.Ramamurthy 35
Driver Manager Class
Provides static, “factory” methods for creating objects implementing the connection interface. Factory methods create objects on
demandwhen a connection is needed to a DB
driver, DriverManager does it using it factory methods.
04/18/23 B.Ramamurthy 36
Connection interface
Connection class represents a session with a specific data source.
Connection object establishes connection to a data source, allocates statement objects, which define and execute SQL statements.
Connection can also get info (metadata) about the data source.
04/18/23 B.Ramamurthy 37
Statement interface
Statement interface is implemented by the connection object.
Statement object provides the workspace for SQL query, executing it, and retrieving returned data.
SELECT {what} FROM {table name} WHERE {criteria} ORDER BY {field}
Queries are embedded as strings in a Statement object.
Types: Statement, PreparedStatement, CallableStatement
04/18/23 B.Ramamurthy 38
ResultSet interface
Results are returned in the form of an object implementing the ResultSet interface.
You may extract individual columns, rows or cell from the ResultSet using the metadata.
04/18/23 B.Ramamurthy 39
JDBC Application Architecture
Application
Connection
Driver Manager
Driver Driver Driver
DataSourceDataSourceDataSource
Statement Result Set
04/18/23 B.Ramamurthy 40
JDBC Programming Steps
Import necessary packages; Ex: import java.sql.*; Load JDBC driver(driver should have been
installed) Data source and its location should have been
registered. Allocate Connection object, Statement object and
ResultSet object Execute query using Statement object Retrieve data from ResultSet object Close Connection object.
04/18/23 B.Ramamurthy 41
Identifying Data Sources
It is specified using URL format.<scheme>: <sub_scheme>:<scheme-
specific-part>Example(for local source):
jdbc:odbc:tech_booksAlternatively, for remote connection,jdbc:odbc://bina.cse.buffalo.edu:4333/
tech_books
Summary
We learned the inner details of the relational database model
We also studied methods for programmatically accessing the data sources from Java language
This is just one persistence model. We will revisit data/storage later on in
the semester in the “big-data” context.
04/18/23 42