1 INTRODUCTION lecture1
2 Data base concept • Data is a meaningless static value. What does 3421 means? • Information is the data you process in a manner that makes it meaningful. Information can be provided only if proper data exists. • A database (DB) is a collection of related persistent data. Can be generated & maintained manually or automatically • Data is what you store in database. • Information is what you retrieve from a database. • A database application is a collection of data and the programs that allow the manipulation of these data to meet the information needs of an enterprise
Database Properties 3  Represents the real world  Logically coherent collection of data.  Designed, built, populated with data for a specific purpose. It has an intended group of users and their applications.  Can be of any size and any degree of complexity.  Can be generated and maintained manually or using a computer. A computerized DB can be created by:  A Group of application programs  Or by Database Management System (DBMS)
•DBMS is a collection of programs that enables users to create, maintain and use a database. • Facilitates the process of: • Defining: specifying data types, structures, & constraints for data. • Manipulating: querying the database to retrieve or update data and generating reports from the data. • Sharing: accessing the database concurrently. • Protects the database and maintains it over a long period of time. • Examples: Oracle, MS Access, DB2, Informix, MySQL, SyBase. What is Database Management System (DBMS) ? 4
• Banking: all transactions. • Hotels: reservation. • Airlines: reservation, schedules. • Libraries: catalog. • Universities: registration, grades. • Sales: customers, products, purchases. • Manufacturing: production, inventory, orders. • Human resources: employee records, salaries. Examples of Databases 5
Database System (DBS) Environment 6 Database Meta-Data Data Access Query Process Application Programs DBMS DBS Database System = Database + DBMS User
7
Database Models • Hirarichal: • This model has a parent–child structure that is similar to an inverted tree, which is what forms the hierarchy, A parent node can have many child nodes, but a child node can have only one parent node 8
9 Database Models • Network: • Data is organized in record types, the logical equivalent of tables in a relational database. Like the hierarchical model, the network model uses an inverted tree structure, but record types are organized into a set structure that relates pairs of record types into owners and members. Any one record type can participate in any set with other record types in the database
Database Models • Relational : • the structure of the relational database is based on the relation, or table, along with the ability to define complex relationships between these relations. Each relation can be accessed directly • At the core of the relational model is the relation. A relation is a set of columns and rows collected in a table-like structure that represents a single entity made up of related data. 10
Normalization • Normalization defines sets of rules, referred to as normal forms, which provide specific guidelines on how data should be organized in order to avoid anomalies that lead to inconsistencies in and loss of data as the data stored in the database is maintained. • 1NF, 2NF, 3NF 11
12 Operations of the Relational Model • Updates: changes the database’s state. • Insert • Delete • Update/modify • Retrievals: does not change the current state of the database.
Operations of the Relational Model • Integrity constraints should not be violated by the update operations. • Several update operations may have to be grouped together. • Updates may propagate to cause other updates automatically. This may be necessary to maintain integrity constraints. 13
14 The Insert Operation • This operation can violate all constraints of the relation. How? • Domain constraint: attribute value does not appear in the corresponding domain. • Key constraint: if the key value already exist in another tuple. • Entity integrity: if the PK of the new tuple is NULL • Referential integrity: if any value of the FK refers to a tuple that does not exist in the other relation.
15 The Delete Operation • This operation can violate only the referential integrity constraint. How? • E.g: you can not delete a course that many students study in already.
16 The Update Operation • The new value must be of the correct data type and domain.
Update Operations on Relations • In case of integrity violation, several actions can be taken: • Cancel the operation that causes the violation (REJECT option) • Perform the operation but inform the user of the violation • Trigger additional updates so the violation is corrected (CASCADE option, SET NULL option) • Execute a user-specified error-correction routine
18 SQL .. An Overview
Overview of SQL 19  Query: allow questions to be asked of the data and display only the information required. It can include info from more the one table  Why Query language? A Database Management system enable users to access and manipulate data using queries.  Structured Query Language (SQL): is the language used by most relational database systems.
Features of SQL 20  What is SQL?  SQL stands for Structured Query Language  SQL lets you access and manipulate databases  SQL is an ANSI (American National Standards Institute) standard
Features of SQL 21  What Can SQL do?  SQL can execute queries against a database  SQL can retrieve data from a database  SQL can insert records in a database  SQL can update records in a database  SQL can delete records from a database  SQL can create new databases  SQL can create new tables in a database  SQL can create stored procedures in a database  SQL can create views in a database  SQL can set permissions on tables, procedures, and views
Features of SQL 22  What Makes SQL Special?  SQL is an English-like language. It uses words such as select, insert, delete as part of its command set  SQL is a non-procedural language: you specify What information you require, not how to get it . This feature makes it easier for you to concentrate on obtaining the desired result.  SQL Processes sets of records rather than a single record at a time.  SQL can be used by a range of users including DBA’s, programmers, Management Personnel, and many other types of end users
Types of SQL Statements 23  Data Definition Language (DDL): Commands that define a database. E.g. CREATE, ALTER, DROP, ...etc.  Data manipulation language (DML): Commands that maintain and query a database. E.g. SELECT, INSERT, UPDATE, DELETE.  Data Control Language (DCL): Commands that control a database, including administering privileges and committing data. E.g. CONNECT, GRANT, REVOKE, ...etc.
24 SQL is relatively easy to learn : • it is non-procedural - you specify what information you require, rather than how to get it; • it is essentially free-format - some sentences do not have to be typed at particular location on screen.
Writing SQL Commands 25 • SQL commands maybe one or more lines • Command words cannot be split across lines • SQL Commands are not case sensitive • Place a semi –colon(;) at the end of last clause.
26 Both give the same result not case sensitive )

data base programming chapter1 26 slides

  • 1.
  • 2.
    2 Data base concept •Data is a meaningless static value. What does 3421 means? • Information is the data you process in a manner that makes it meaningful. Information can be provided only if proper data exists. • A database (DB) is a collection of related persistent data. Can be generated & maintained manually or automatically • Data is what you store in database. • Information is what you retrieve from a database. • A database application is a collection of data and the programs that allow the manipulation of these data to meet the information needs of an enterprise
  • 3.
    Database Properties 3  Representsthe real world  Logically coherent collection of data.  Designed, built, populated with data for a specific purpose. It has an intended group of users and their applications.  Can be of any size and any degree of complexity.  Can be generated and maintained manually or using a computer. A computerized DB can be created by:  A Group of application programs  Or by Database Management System (DBMS)
  • 4.
    •DBMS is acollection of programs that enables users to create, maintain and use a database. • Facilitates the process of: • Defining: specifying data types, structures, & constraints for data. • Manipulating: querying the database to retrieve or update data and generating reports from the data. • Sharing: accessing the database concurrently. • Protects the database and maintains it over a long period of time. • Examples: Oracle, MS Access, DB2, Informix, MySQL, SyBase. What is Database Management System (DBMS) ? 4
  • 5.
    • Banking: alltransactions. • Hotels: reservation. • Airlines: reservation, schedules. • Libraries: catalog. • Universities: registration, grades. • Sales: customers, products, purchases. • Manufacturing: production, inventory, orders. • Human resources: employee records, salaries. Examples of Databases 5
  • 6.
    Database System (DBS)Environment 6 Database Meta-Data Data Access Query Process Application Programs DBMS DBS Database System = Database + DBMS User
  • 7.
  • 8.
    Database Models • Hirarichal: •This model has a parent–child structure that is similar to an inverted tree, which is what forms the hierarchy, A parent node can have many child nodes, but a child node can have only one parent node 8
  • 9.
    9 Database Models • Network: •Data is organized in record types, the logical equivalent of tables in a relational database. Like the hierarchical model, the network model uses an inverted tree structure, but record types are organized into a set structure that relates pairs of record types into owners and members. Any one record type can participate in any set with other record types in the database
  • 10.
    Database Models • Relational: • the structure of the relational database is based on the relation, or table, along with the ability to define complex relationships between these relations. Each relation can be accessed directly • At the core of the relational model is the relation. A relation is a set of columns and rows collected in a table-like structure that represents a single entity made up of related data. 10
  • 11.
    Normalization • Normalization definessets of rules, referred to as normal forms, which provide specific guidelines on how data should be organized in order to avoid anomalies that lead to inconsistencies in and loss of data as the data stored in the database is maintained. • 1NF, 2NF, 3NF 11
  • 12.
    12 Operations of theRelational Model • Updates: changes the database’s state. • Insert • Delete • Update/modify • Retrievals: does not change the current state of the database.
  • 13.
    Operations of theRelational Model • Integrity constraints should not be violated by the update operations. • Several update operations may have to be grouped together. • Updates may propagate to cause other updates automatically. This may be necessary to maintain integrity constraints. 13
  • 14.
    14 The Insert Operation •This operation can violate all constraints of the relation. How? • Domain constraint: attribute value does not appear in the corresponding domain. • Key constraint: if the key value already exist in another tuple. • Entity integrity: if the PK of the new tuple is NULL • Referential integrity: if any value of the FK refers to a tuple that does not exist in the other relation.
  • 15.
    15 The Delete Operation •This operation can violate only the referential integrity constraint. How? • E.g: you can not delete a course that many students study in already.
  • 16.
    16 The Update Operation •The new value must be of the correct data type and domain.
  • 17.
    Update Operations onRelations • In case of integrity violation, several actions can be taken: • Cancel the operation that causes the violation (REJECT option) • Perform the operation but inform the user of the violation • Trigger additional updates so the violation is corrected (CASCADE option, SET NULL option) • Execute a user-specified error-correction routine
  • 18.
    18 SQL .. AnOverview
  • 19.
    Overview of SQL 19 Query: allow questions to be asked of the data and display only the information required. It can include info from more the one table  Why Query language? A Database Management system enable users to access and manipulate data using queries.  Structured Query Language (SQL): is the language used by most relational database systems.
  • 20.
    Features of SQL 20 What is SQL?  SQL stands for Structured Query Language  SQL lets you access and manipulate databases  SQL is an ANSI (American National Standards Institute) standard
  • 21.
    Features of SQL 21 What Can SQL do?  SQL can execute queries against a database  SQL can retrieve data from a database  SQL can insert records in a database  SQL can update records in a database  SQL can delete records from a database  SQL can create new databases  SQL can create new tables in a database  SQL can create stored procedures in a database  SQL can create views in a database  SQL can set permissions on tables, procedures, and views
  • 22.
    Features of SQL 22 What Makes SQL Special?  SQL is an English-like language. It uses words such as select, insert, delete as part of its command set  SQL is a non-procedural language: you specify What information you require, not how to get it . This feature makes it easier for you to concentrate on obtaining the desired result.  SQL Processes sets of records rather than a single record at a time.  SQL can be used by a range of users including DBA’s, programmers, Management Personnel, and many other types of end users
  • 23.
    Types of SQLStatements 23  Data Definition Language (DDL): Commands that define a database. E.g. CREATE, ALTER, DROP, ...etc.  Data manipulation language (DML): Commands that maintain and query a database. E.g. SELECT, INSERT, UPDATE, DELETE.  Data Control Language (DCL): Commands that control a database, including administering privileges and committing data. E.g. CONNECT, GRANT, REVOKE, ...etc.
  • 24.
    24 SQL is relativelyeasy to learn : • it is non-procedural - you specify what information you require, rather than how to get it; • it is essentially free-format - some sentences do not have to be typed at particular location on screen.
  • 25.
    Writing SQL Commands 25 •SQL commands maybe one or more lines • Command words cannot be split across lines • SQL Commands are not case sensitive • Place a semi –colon(;) at the end of last clause.
  • 26.
    26 Both give thesame result not case sensitive )