Database Management Systems 2009/10
                         – Chapter 1: Introduction –


                                   J. Gamper



  ◮   The Course
  ◮   The DB Field
  ◮   Basic Definitions
  ◮   The Relational Data Model
  ◮   Accessing DBs

 These slides were developed by:
 – Michael B¨hlen, University of Zurich, Switzerland
             o
 – Johann Gamper, University of Bozen-Bolzano, Italy

DMS 2009/10                              J. Gamper     1/24
The Course



  ◮   Course page
         ◮    http://www.inf.unibz.it/dis/teaching/DMS
  ◮   The slides are based on the following text books and associated material:
         ◮    A. Silberschatz, H. Korth, and S. Sudarshan: Database System Concept, 5
              edition, McGraw Hill, 2006.
         ◮    R. Elmasri and S.B. Navathe: Fundamentals of Database Systems, 4th
              edition, Pearson Addison Wesley, 2004.
  ◮   Additional Book
         ◮    Garcia-Molina, Ullman,Widom: Database Systems: The Complete Book,
              Prentice-Hall, 2002.




DMS 2009/10                                  J. Gamper                             2/24
The Course Content

  ◮   Storage and File Structure
         ◮    Physical Storage media, file and buffer manager
  ◮   Indexing and Hashing
         ◮    Ordered indices, B-trees, hashing
  ◮   Query Processing
         ◮    Measures of query cost, selection and join operation
  ◮   Query Optimization
         ◮    Transformation of relational expressions, evaluation plans
  ◮   Transactions
         ◮    ACID properties, SQL transactions
  ◮   Concurrency Control
         ◮    Lock-/timestamp-/validation-based protocols
  ◮   Recovery System
         ◮    Log-based recovery, shadow paging



DMS 2009/10                                       J. Gamper                3/24
The DB Field
  ◮   Journal Publications
         ◮    ACM Transaction on Database System (TODS)
         ◮    IEEE Transactions on Knowledge and Data Engineering (TKDE)
         ◮    The VLDB Journal
         ◮    Information Systems
  ◮   Conference Publications
         ◮    SIGMOD
         ◮    VLDB
         ◮    EDBT
         ◮    ICDE
  ◮   DB & LP Bibliography (Michael Ley, Uni Trier, Germany)
         ◮    http://www.informatik.uni-trier.de/˜ley/db/
  ◮   Commercial Products
         ◮    Oracle
         ◮    DB2 (IBM)
         ◮    Microsoft SQL Server
         ◮    Postgres
         ◮    Sybase
         ◮    Ingres
         ◮    Informix
         ◮    PC “DBMSs”: Paradox, Access, ...
DMS 2009/10                                   J. Gamper                    4/24
Basic Definitions



   ◮   Mini-world: The part of the real world we are interested in
   ◮   Data: Known facts about the mini-world that can be recorded
   ◮   Database (DB): A collection of related data
   ◮   Database Management System (DBMS): A software package to
       facilitate the creation/maintenance of databases
   ◮   Database System: DB + DBMS
   ◮   Meta Data: Information about the structure of the DB.
          ◮    Meta data is organized as a DB itself.




 DMS 2009/10                                    J. Gamper            5/24
Basic Definitions . . .



   ◮   A DBMS provides two kind of languages
          ◮    A data definition language (DDL) for specifying the database schema
                 ◮   the database schema is stored in the data dictionary
                 ◮   the content of data dictionary is called metadata
          ◮    A data manipulation language (DML) for updating and querying
               databases, i.e.,
                 ◮   retrieval of information
                 ◮   insertion of new information
                 ◮   deletion of information
                 ◮   modification of information




 DMS 2009/10                                        J. Gamper                       6/24
ANSI/SPARC Architecture

  ◮   The ANSI/SPARC three level schema architecture was designed to achieve
         ◮    program/data independence
         ◮    multiple user views
  ◮   Schemes are defined at 3 levels
         ◮    external level: describes various
              user views for parts of the
              database; often uses the logical
              schema
         ◮    logical level: describes the
              structure and constraints for the
              whole database; uses a logical
              schema
         ◮    internal level: describes data
              storage structures and access
              paths; uses a physical schema




DMS 2009/10                                       J. Gamper               7/24
DBMS Functionality



  ◮   Stores and retrieves data
  ◮   Controls redundancy
  ◮   Ensures data consistency
  ◮   Enables sharing of data by multiple applications
  ◮   Supports concurrent access by multiple users
  ◮   Protects against loss of data
  ◮   Ensures security
  ◮   etc.




DMS 2009/10                              J. Gamper       8/24
Aspects of DB Research and Practice

   ◮   Design of languages
   ◮   Development of algorithms
   ◮   Data modeling
   ◮   User interface design
   ◮   Design of migration strategies
   ◮   Distributed databases
   ◮   Handling huge volumes of data
   ◮   New data models and systems
          ◮    XML/semi-structured databases
          ◮    Stream data processing
          ◮    Temporal and spatial databases
          ◮    GIS systems
   ◮   etc.



 DMS 2009/10                                    J. Gamper   9/24
Databases – Pros and Cons

   ◮   Pros                                                     ◮   Cons
          ◮    Logical                                               ◮   Huge and complex systems
          ◮    Data abstraction                                      ◮   Restrict functionality
          ◮    Meta reasoning                                        ◮   Substantial overhead
          ◮    Self describing, e.g., data dictionary                ◮   No direct data access
          ◮    Multiple user views
          ◮    Data sharing

   ◮   When not to use a DBMS
          ◮    Too high costs
                 ◮   High intitial investment (software, hardware, training)
                 ◮   Overhead for providing generality, security, recovery, integrity, and
                     concurrency
          ◮    Simple, well defined, and not-changing application
          ◮    No multi-user access required
          ◮    Stringent real-time requirements



 DMS 2009/10                                        J. Gamper                                  10/24
Relational Data Model
   ◮   Data are stored in relations/tables
         employee
         Name Dept        Salary
         Tom      SE      23K
         Lena     DB      33K

         department
         Dname Manager          Address
         SE       Tom           Boston
         DB       Lena          Tucson

         project
         Pid Dept      From          To
         14     SE     01.01.2005    31.12.2005
         173 SE        15.04.2005    30.10.2006
         201 DB        15.04.2005    31.03.2006


 DMS 2009/10                                 J. Gamper   11/24
Relational Data Model . . .



   ◮   A domain D is a set of atomic data values.
          ◮    phone numbers,CPR numbers, names, grades, birthdates, departments,
               {i,o,x,?,-}
          ◮    each domain includes the special value null for unknown or missing value
   ◮   With each domain a data type or format is specified.
          ◮    5 digit integers, yyyy-mm-dd, characters
   ◮   An attribute Ai describes the role of a domain in a relation schema.
          ◮    PhoneNr, Age, DeptName




 DMS 2009/10                                   J. Gamper                             12/24
Relational Data Model . . .


   ◮   A relation schema R(A1 , ..., An ) is made up of a relation name R and a
       list of attributes.
          ◮    employee(Name, Dept, Salary )
   ◮   A tuple t is an ordered list of values, i.e., t = (v1 , ..., vn ) with
       vi ∈ dom(Ai ).
          ◮    t = (Tom, SE , 23K )
   ◮   A relation r of the relation schema R(A1 , ..., An ) is a set of n-ary tuples.
          ◮    r = {(Tom, SE , 23K ), (Lene, DB, 33K )}
   ◮   A database DB is a set of relations.
          ◮    DB = {r , s, ...}
          ◮    r = {(Tom, SE , 23K ), (Lene, DB, 33K )}
          ◮    s = {(SE , Tom, Boston), (DB, Lena, Tucson)}




 DMS 2009/10                                   J. Gamper                            13/24
Properties of Relations




   ◮   A relation is a set of tuples, i.e.,
          ◮    no ordering between tuples and
          ◮    no duplicates (identical tuples) exist.
   ◮   Attributes within tuples are ordered
          ◮    At the logical level it is possible to have unordered tuples if the
               correspondence between values and attributes is maintained
          ◮    e.g., {Salary /23K , Name/Tom, Dept/SE }




 DMS 2009/10                                     J. Gamper                           14/24
Accessing DBs




  ◮   The success of DBs also depends on the ease of data access.
  ◮   When accessing a (relational) DB two factors must be taken into account.
         ◮    The impedence mismatch.
         ◮    The interface to the DB.




DMS 2009/10                              J. Gamper                         15/24
Impedence Mismatch
  ◮   Impedence mismatch: The difference between the data models used in
      the application and in the DB, e.g., sets vs. records




  ◮   Cursor
         ◮    The most versatile way to connect a DB to a host language.
         ◮    Cursors are used to resolve the impedance mismatch.
         ◮    A cursor runs through the tuples of a relation/table.




DMS 2009/10                                  J. Gamper                     16/24
DB Interfaces




   ◮   Various interfaces to DBs exist, e.g.,
          ◮    Terminal interface (sqlplus, etc.)
          ◮    OCI (Oracle Call Interface)
          ◮    X/Open SQL CLI (Call Level Interface)
          ◮    ODBC (Open Data Base Connection), iODBC for Unix
          ◮    JDBC (Java Database Connectivity)
          ◮    DBI (Perl DB Interface)
          ◮    Embedded SQL




 DMS 2009/10                               J. Gamper              17/24
Oracle’s OCI



   ◮   The OCI is a set of C procedures to access an Oracle database e.g.,
          ◮    olon
          ◮    oparse
          ◮    oexec
          ◮    ologof
          ◮    odescr
          ◮    ofetch
          ◮    oopen
          ◮    odefin
          ◮    oclose
          ◮    obndrn




 DMS 2009/10                             J. Gamper                           18/24
Oracle’s OCI . . .
#include <ocidfn.h>
Lda Def lda;
Cda Def cda;
main() {
  orlon(&lda,hda,"scott",-1,"tiger",-1,0);
  oopen(&cda,&lda,0,-1,-1,0,-1);
  oparse(&cda,"SELECT * FROM cat",-1,0,2);
  odefin(&cda,1,&name,30,,-1,0,0,-1,-1,0,0);
  odefin(&cda,2,&type,30,,-1,0,0,-1,-1,0,0);

    oexec(&cda);
    for (;;) {
      if (ofetch(&cda1)) break;
        printf(" %s %s ", name, type);
    }

    oclose(&cda);
    ologof(&lda);
}

 DMS 2009/10                         J. Gamper   19/24
ODBC

  ◮   ODBC is a set of C procedures to access any(!) SQL database, e.g.,
         ◮    SQLAllocEnv
         ◮    SQLAllocStmt
         ◮    SQLDescribeCol
         ◮    SQLAllocConnect
         ◮    SQLPrepare
         ◮    SQLBindCol
         ◮    SQLConnect
         ◮    SQLSetParam
         ◮    SQLFetch
         ◮    SQLDisconnect
         ◮    SQLExecute
         ◮    SQLFreeConnect
         ◮    SQLExecDirect
         ◮    SQLFreeEnv
         ◮    SQLFreeStmt
  ◮   ODBC supports meta data.


DMS 2009/10                            J. Gamper                           20/24
ODBC . . .
#include <sqlcli .h>
SQLHENV e;
SQLHDBC c;
SQLHSTMT s;

int main() {
  SQLAllocEnv(&e);
  SQLAllocConnect(e,&c);
  SQLConnect(c, "ora1", SQL NTS, "scott", SQL NTS, "tiger", SQL NTS);
  SQLAllocStmt(c,&s);
  SQLPrepare(s,"select * from cat", SQL NTS);
  SQLExecute(s);
  SQLBindCol(s,1,SQL C CHAR,name,30,NULL);
  SQLBindCol(s,2,SQL C CHAR,type,30,NULL);

    SQLFetch(s);
    printf("%s %s", name, type);

    SQLFreeStmt(s,SQL DROP);
    SQLDisconnect(c);
    SQLFreeConnect(c);
    SQLFreeEnv(e);
}

 DMS 2009/10                           J. Gamper                        21/24
JDBC Interface


   ◮   JDBC is a set of Java procedures to access any(!) SQL database, e.g.,
          ◮    getConnection
          ◮    execute
          ◮    getColumnName
          ◮    createStatement
          ◮    exectueQuery
          ◮    getColumnType
          ◮    close
          ◮    executeUpdate
          ◮    getString
          ◮    getResultSet
          ◮    getObject
   ◮   JDBC supports meta data.




 DMS 2009/10                             J. Gamper                             22/24
JDBC Interface . . .
import java.sql.*;
class demo {

    public static void main (String args [])
        throws SQLException,ClassNotFoundException {

        // Load the Oracle JDBC driver
        Class.forName("oracle.jdbc.driver.OracleDriver");

        // Connect to the database
        Connection conn = DriverManager.getConnection(
          "jdbc:oracle:thin:@femto:1526:ora1", "scott", "tiger");

        // Create a statement
        Statement stmt = conn.createStatement ();
        // Insert a tuple into a relation
        stmt.execute("insert into r values(1,’abc’)");
        // Executes a query and displays the result
        ResultSet rset = stmt.executeQuery ("select * from r");
        while (rset.next())
          System.out.println(rset.getInt(1) + " " + rset.getString(2));
    }
}

 DMS 2009/10                               J. Gamper                      23/24
Embedded SQL




  ◮   Extended versions of, e.g., C, Pascal, and Fortran allow to embed SQL
      statements.
  ◮   A precompiler compiles these languages to, e.g., C with OCI library calls.
  ◮   The idea is that C with embedded SQL is easier to use than C with OCI
      calls.
  ◮   Embedded SQL is standardized (ISO, ANSI).




DMS 2009/10                              J. Gamper                             24/24

More Related Content

PPT
D B M S Animate
PPTX
DOC
Basic IMS For Applications
PPTX
RDBMS
PDF
2 database system concepts and architecture
PPTX
Lesson 2 network database system
DOC
rdbms-notes
D B M S Animate
Basic IMS For Applications
RDBMS
2 database system concepts and architecture
Lesson 2 network database system
rdbms-notes

What's hot (19)

PPTX
IMS concepts
PPT
Database system concepts and architecture
PPTX
PPTX
Veena
PPSX
IM02: Database Language
PDF
DDBMS Paper with Solution
PPTX
Distributed Database Management System
PDF
5 data storage_and_indexing
PPTX
3 db architecture
PPT
Unit 08 dbms
PPT
Unit 04 dbms
PPTX
A concept of dbms
PPTX
Cp 121 lecture 01
PPT
"Diffrence between RDBMS, OODBMS and ORDBMS"
PPT
Lecture 02 architecture of dbms
PPT
ODP
Implementation Issue with ORDBMS
IMS concepts
Database system concepts and architecture
Veena
IM02: Database Language
DDBMS Paper with Solution
Distributed Database Management System
5 data storage_and_indexing
3 db architecture
Unit 08 dbms
Unit 04 dbms
A concept of dbms
Cp 121 lecture 01
"Diffrence between RDBMS, OODBMS and ORDBMS"
Lecture 02 architecture of dbms
Implementation Issue with ORDBMS
Ad

Viewers also liked (9)

PPTX
Texas s ta r chart
PDF
01 intro
PPT
Mics capital presentation
PPT
ER model
DOCX
PDF
Relatório de desempenho digital intergastro
PPTX
Texas s ta r chart
PDF
Sql smart reference_by_prasad
PDF
Sql smart reference_by_prasad
Texas s ta r chart
01 intro
Mics capital presentation
ER model
Relatório de desempenho digital intergastro
Texas s ta r chart
Sql smart reference_by_prasad
Sql smart reference_by_prasad
Ad

Similar to Dms01 (20)

PPT
Database management system overview
PPTX
Database Management Systems Lecture # 01
PPTX
COMP303-Lecture-01_1539277777777777.pptx
PPTX
PPTX
Database-management-system-dbms-ppt.pptx
PPTX
BM322_03.pptx123456786546654525165654646564
PDF
PPTX
Database-management-system-dbms-ppt.pptx
PPTX
Lecture 1.pptx
PPTX
Database Management System ppt
PDF
csedatabasemanagementsystemppt-170825044344.pdf
PPT
Unit01 dbms
PPTX
Kskv kutch university DBMS unit 1 basic concepts, data,information,database,...
PPT
27 fcs157al2
PPTX
Fundamentals of database system - Database System Concepts and Architecture
PPTX
Complete first chapter rdbm 17332
PPTX
databasesystemsconollyslide1-151102101031-lva1-app6892.pptx
PPTX
Database_Systems_(CSC_206)_-_2024-2025_STU_PT_1.pptx
PPTX
Lecture 1-Introduction to Database Management Systems.pptx
PPTX
Basic Concept of Database
Database management system overview
Database Management Systems Lecture # 01
COMP303-Lecture-01_1539277777777777.pptx
Database-management-system-dbms-ppt.pptx
BM322_03.pptx123456786546654525165654646564
Database-management-system-dbms-ppt.pptx
Lecture 1.pptx
Database Management System ppt
csedatabasemanagementsystemppt-170825044344.pdf
Unit01 dbms
Kskv kutch university DBMS unit 1 basic concepts, data,information,database,...
27 fcs157al2
Fundamentals of database system - Database System Concepts and Architecture
Complete first chapter rdbm 17332
databasesystemsconollyslide1-151102101031-lva1-app6892.pptx
Database_Systems_(CSC_206)_-_2024-2025_STU_PT_1.pptx
Lecture 1-Introduction to Database Management Systems.pptx
Basic Concept of Database

Recently uploaded (20)

PPTX
2018-HIPAA-Renewal-Training for executives
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
Five Habits of High-Impact Board Members
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Architecture types and enterprise applications.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PPTX
TEXTILE technology diploma scope and career opportunities
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
2018-HIPAA-Renewal-Training for executives
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Five Habits of High-Impact Board Members
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
A contest of sentiment analysis: k-nearest neighbor versus neural network
sbt 2.0: go big (Scala Days 2025 edition)
NewMind AI Weekly Chronicles – August ’25 Week III
Architecture types and enterprise applications.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Module 1.ppt Iot fundamentals and Architecture
1 - Historical Antecedents, Social Consideration.pdf
Convolutional neural network based encoder-decoder for efficient real-time ob...
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
TEXTILE technology diploma scope and career opportunities
UiPath Agentic Automation session 1: RPA to Agents
Comparative analysis of machine learning models for fake news detection in so...
Taming the Chaos: How to Turn Unstructured Data into Decisions
Enhancing plagiarism detection using data pre-processing and machine learning...
sustainability-14-14877-v2.pddhzftheheeeee

Dms01

  • 1. Database Management Systems 2009/10 – Chapter 1: Introduction – J. Gamper ◮ The Course ◮ The DB Field ◮ Basic Definitions ◮ The Relational Data Model ◮ Accessing DBs These slides were developed by: – Michael B¨hlen, University of Zurich, Switzerland o – Johann Gamper, University of Bozen-Bolzano, Italy DMS 2009/10 J. Gamper 1/24
  • 2. The Course ◮ Course page ◮ http://www.inf.unibz.it/dis/teaching/DMS ◮ The slides are based on the following text books and associated material: ◮ A. Silberschatz, H. Korth, and S. Sudarshan: Database System Concept, 5 edition, McGraw Hill, 2006. ◮ R. Elmasri and S.B. Navathe: Fundamentals of Database Systems, 4th edition, Pearson Addison Wesley, 2004. ◮ Additional Book ◮ Garcia-Molina, Ullman,Widom: Database Systems: The Complete Book, Prentice-Hall, 2002. DMS 2009/10 J. Gamper 2/24
  • 3. The Course Content ◮ Storage and File Structure ◮ Physical Storage media, file and buffer manager ◮ Indexing and Hashing ◮ Ordered indices, B-trees, hashing ◮ Query Processing ◮ Measures of query cost, selection and join operation ◮ Query Optimization ◮ Transformation of relational expressions, evaluation plans ◮ Transactions ◮ ACID properties, SQL transactions ◮ Concurrency Control ◮ Lock-/timestamp-/validation-based protocols ◮ Recovery System ◮ Log-based recovery, shadow paging DMS 2009/10 J. Gamper 3/24
  • 4. The DB Field ◮ Journal Publications ◮ ACM Transaction on Database System (TODS) ◮ IEEE Transactions on Knowledge and Data Engineering (TKDE) ◮ The VLDB Journal ◮ Information Systems ◮ Conference Publications ◮ SIGMOD ◮ VLDB ◮ EDBT ◮ ICDE ◮ DB & LP Bibliography (Michael Ley, Uni Trier, Germany) ◮ http://www.informatik.uni-trier.de/˜ley/db/ ◮ Commercial Products ◮ Oracle ◮ DB2 (IBM) ◮ Microsoft SQL Server ◮ Postgres ◮ Sybase ◮ Ingres ◮ Informix ◮ PC “DBMSs”: Paradox, Access, ... DMS 2009/10 J. Gamper 4/24
  • 5. Basic Definitions ◮ Mini-world: The part of the real world we are interested in ◮ Data: Known facts about the mini-world that can be recorded ◮ Database (DB): A collection of related data ◮ Database Management System (DBMS): A software package to facilitate the creation/maintenance of databases ◮ Database System: DB + DBMS ◮ Meta Data: Information about the structure of the DB. ◮ Meta data is organized as a DB itself. DMS 2009/10 J. Gamper 5/24
  • 6. Basic Definitions . . . ◮ A DBMS provides two kind of languages ◮ A data definition language (DDL) for specifying the database schema ◮ the database schema is stored in the data dictionary ◮ the content of data dictionary is called metadata ◮ A data manipulation language (DML) for updating and querying databases, i.e., ◮ retrieval of information ◮ insertion of new information ◮ deletion of information ◮ modification of information DMS 2009/10 J. Gamper 6/24
  • 7. ANSI/SPARC Architecture ◮ The ANSI/SPARC three level schema architecture was designed to achieve ◮ program/data independence ◮ multiple user views ◮ Schemes are defined at 3 levels ◮ external level: describes various user views for parts of the database; often uses the logical schema ◮ logical level: describes the structure and constraints for the whole database; uses a logical schema ◮ internal level: describes data storage structures and access paths; uses a physical schema DMS 2009/10 J. Gamper 7/24
  • 8. DBMS Functionality ◮ Stores and retrieves data ◮ Controls redundancy ◮ Ensures data consistency ◮ Enables sharing of data by multiple applications ◮ Supports concurrent access by multiple users ◮ Protects against loss of data ◮ Ensures security ◮ etc. DMS 2009/10 J. Gamper 8/24
  • 9. Aspects of DB Research and Practice ◮ Design of languages ◮ Development of algorithms ◮ Data modeling ◮ User interface design ◮ Design of migration strategies ◮ Distributed databases ◮ Handling huge volumes of data ◮ New data models and systems ◮ XML/semi-structured databases ◮ Stream data processing ◮ Temporal and spatial databases ◮ GIS systems ◮ etc. DMS 2009/10 J. Gamper 9/24
  • 10. Databases – Pros and Cons ◮ Pros ◮ Cons ◮ Logical ◮ Huge and complex systems ◮ Data abstraction ◮ Restrict functionality ◮ Meta reasoning ◮ Substantial overhead ◮ Self describing, e.g., data dictionary ◮ No direct data access ◮ Multiple user views ◮ Data sharing ◮ When not to use a DBMS ◮ Too high costs ◮ High intitial investment (software, hardware, training) ◮ Overhead for providing generality, security, recovery, integrity, and concurrency ◮ Simple, well defined, and not-changing application ◮ No multi-user access required ◮ Stringent real-time requirements DMS 2009/10 J. Gamper 10/24
  • 11. Relational Data Model ◮ Data are stored in relations/tables employee Name Dept Salary Tom SE 23K Lena DB 33K department Dname Manager Address SE Tom Boston DB Lena Tucson project Pid Dept From To 14 SE 01.01.2005 31.12.2005 173 SE 15.04.2005 30.10.2006 201 DB 15.04.2005 31.03.2006 DMS 2009/10 J. Gamper 11/24
  • 12. Relational Data Model . . . ◮ A domain D is a set of atomic data values. ◮ phone numbers,CPR numbers, names, grades, birthdates, departments, {i,o,x,?,-} ◮ each domain includes the special value null for unknown or missing value ◮ With each domain a data type or format is specified. ◮ 5 digit integers, yyyy-mm-dd, characters ◮ An attribute Ai describes the role of a domain in a relation schema. ◮ PhoneNr, Age, DeptName DMS 2009/10 J. Gamper 12/24
  • 13. Relational Data Model . . . ◮ A relation schema R(A1 , ..., An ) is made up of a relation name R and a list of attributes. ◮ employee(Name, Dept, Salary ) ◮ A tuple t is an ordered list of values, i.e., t = (v1 , ..., vn ) with vi ∈ dom(Ai ). ◮ t = (Tom, SE , 23K ) ◮ A relation r of the relation schema R(A1 , ..., An ) is a set of n-ary tuples. ◮ r = {(Tom, SE , 23K ), (Lene, DB, 33K )} ◮ A database DB is a set of relations. ◮ DB = {r , s, ...} ◮ r = {(Tom, SE , 23K ), (Lene, DB, 33K )} ◮ s = {(SE , Tom, Boston), (DB, Lena, Tucson)} DMS 2009/10 J. Gamper 13/24
  • 14. Properties of Relations ◮ A relation is a set of tuples, i.e., ◮ no ordering between tuples and ◮ no duplicates (identical tuples) exist. ◮ Attributes within tuples are ordered ◮ At the logical level it is possible to have unordered tuples if the correspondence between values and attributes is maintained ◮ e.g., {Salary /23K , Name/Tom, Dept/SE } DMS 2009/10 J. Gamper 14/24
  • 15. Accessing DBs ◮ The success of DBs also depends on the ease of data access. ◮ When accessing a (relational) DB two factors must be taken into account. ◮ The impedence mismatch. ◮ The interface to the DB. DMS 2009/10 J. Gamper 15/24
  • 16. Impedence Mismatch ◮ Impedence mismatch: The difference between the data models used in the application and in the DB, e.g., sets vs. records ◮ Cursor ◮ The most versatile way to connect a DB to a host language. ◮ Cursors are used to resolve the impedance mismatch. ◮ A cursor runs through the tuples of a relation/table. DMS 2009/10 J. Gamper 16/24
  • 17. DB Interfaces ◮ Various interfaces to DBs exist, e.g., ◮ Terminal interface (sqlplus, etc.) ◮ OCI (Oracle Call Interface) ◮ X/Open SQL CLI (Call Level Interface) ◮ ODBC (Open Data Base Connection), iODBC for Unix ◮ JDBC (Java Database Connectivity) ◮ DBI (Perl DB Interface) ◮ Embedded SQL DMS 2009/10 J. Gamper 17/24
  • 18. Oracle’s OCI ◮ The OCI is a set of C procedures to access an Oracle database e.g., ◮ olon ◮ oparse ◮ oexec ◮ ologof ◮ odescr ◮ ofetch ◮ oopen ◮ odefin ◮ oclose ◮ obndrn DMS 2009/10 J. Gamper 18/24
  • 19. Oracle’s OCI . . . #include <ocidfn.h> Lda Def lda; Cda Def cda; main() { orlon(&lda,hda,"scott",-1,"tiger",-1,0); oopen(&cda,&lda,0,-1,-1,0,-1); oparse(&cda,"SELECT * FROM cat",-1,0,2); odefin(&cda,1,&name,30,,-1,0,0,-1,-1,0,0); odefin(&cda,2,&type,30,,-1,0,0,-1,-1,0,0); oexec(&cda); for (;;) { if (ofetch(&cda1)) break; printf(" %s %s ", name, type); } oclose(&cda); ologof(&lda); } DMS 2009/10 J. Gamper 19/24
  • 20. ODBC ◮ ODBC is a set of C procedures to access any(!) SQL database, e.g., ◮ SQLAllocEnv ◮ SQLAllocStmt ◮ SQLDescribeCol ◮ SQLAllocConnect ◮ SQLPrepare ◮ SQLBindCol ◮ SQLConnect ◮ SQLSetParam ◮ SQLFetch ◮ SQLDisconnect ◮ SQLExecute ◮ SQLFreeConnect ◮ SQLExecDirect ◮ SQLFreeEnv ◮ SQLFreeStmt ◮ ODBC supports meta data. DMS 2009/10 J. Gamper 20/24
  • 21. ODBC . . . #include <sqlcli .h> SQLHENV e; SQLHDBC c; SQLHSTMT s; int main() { SQLAllocEnv(&e); SQLAllocConnect(e,&c); SQLConnect(c, "ora1", SQL NTS, "scott", SQL NTS, "tiger", SQL NTS); SQLAllocStmt(c,&s); SQLPrepare(s,"select * from cat", SQL NTS); SQLExecute(s); SQLBindCol(s,1,SQL C CHAR,name,30,NULL); SQLBindCol(s,2,SQL C CHAR,type,30,NULL); SQLFetch(s); printf("%s %s", name, type); SQLFreeStmt(s,SQL DROP); SQLDisconnect(c); SQLFreeConnect(c); SQLFreeEnv(e); } DMS 2009/10 J. Gamper 21/24
  • 22. JDBC Interface ◮ JDBC is a set of Java procedures to access any(!) SQL database, e.g., ◮ getConnection ◮ execute ◮ getColumnName ◮ createStatement ◮ exectueQuery ◮ getColumnType ◮ close ◮ executeUpdate ◮ getString ◮ getResultSet ◮ getObject ◮ JDBC supports meta data. DMS 2009/10 J. Gamper 22/24
  • 23. JDBC Interface . . . import java.sql.*; class demo { public static void main (String args []) throws SQLException,ClassNotFoundException { // Load the Oracle JDBC driver Class.forName("oracle.jdbc.driver.OracleDriver"); // Connect to the database Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@femto:1526:ora1", "scott", "tiger"); // Create a statement Statement stmt = conn.createStatement (); // Insert a tuple into a relation stmt.execute("insert into r values(1,’abc’)"); // Executes a query and displays the result ResultSet rset = stmt.executeQuery ("select * from r"); while (rset.next()) System.out.println(rset.getInt(1) + " " + rset.getString(2)); } } DMS 2009/10 J. Gamper 23/24
  • 24. Embedded SQL ◮ Extended versions of, e.g., C, Pascal, and Fortran allow to embed SQL statements. ◮ A precompiler compiles these languages to, e.g., C with OCI library calls. ◮ The idea is that C with embedded SQL is easier to use than C with OCI calls. ◮ Embedded SQL is standardized (ISO, ANSI). DMS 2009/10 J. Gamper 24/24