Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Fg d


Published on

Published in: Business
  • Be the first to comment

  • Be the first to like this

Fg d

  1. 1. Information Systems: Creating Business Value by Mark Huber, Craig Piercy, and Patrick McKeown Field Guide D: The Details of SQL, Data Modeling, and XML
  2. 2. Student ROI (Return on Investment) <ul><li>Your investment of time and effort in this course will result in your being able to answer these questions: </li></ul><ul><li>How do knowledge workers use SQL to query a single-table database? </li></ul><ul><li>How do knowledge workers use logical modeling to create effective relational database systems? </li></ul><ul><li>How is SQL used to query multiple-table databases? </li></ul><ul><li>How do knowledge workers use XML to transfer data between software applications? </li></ul>
  3. 3. What We Will Cover: <ul><li>Using SQL to Query Relational Databases </li></ul><ul><li>Using Logical Modeling to Create a Relational Database </li></ul><ul><li>Querying Multitable Databases </li></ul><ul><li>Using XML for Data Transfer </li></ul>
  4. 4. File Processing Systems <ul><li>Before the development of database systems, most organizations used file processing systems. </li></ul><ul><li>With file processing , each application uses it own set of files. </li></ul><ul><li>Even though files may be related by an application, they are not necessarily stored or managed together. </li></ul>
  5. 5. The Data Hierarchy <ul><li>The data hierarchy is a way of organizing stored data in progressively larger levels of complexity </li></ul><ul><li>Bit Record </li></ul><ul><li>Character File </li></ul><ul><li>Field Database </li></ul>
  6. 6. Database Systems <ul><li>A database and its DBMS is often referred to as a database system. </li></ul><ul><li>People who create and manage organizational database systems are referred to as database administrators. </li></ul><ul><li>Knowledge workers usually use application software to access and query the database. </li></ul>
  7. 7. DBMSs Control Database Access
  8. 8. Disadvantages of File Processing Systems <ul><li>Data Redundancy: Files stored in multiple locations, so can have inconsistent data due to changes not being made to all files. </li></ul><ul><li>Data Dependence: Files work with specific applications but may not work with others. </li></ul><ul><li>Data Inaccessibility: Data may be difficult to access by other applications. </li></ul><ul><li>Poor File Management: Difficult to manage files for simultaneous use, secure files, and recover from file problems. </li></ul>
  9. 9. Advantages of Database Management Systems <ul><li>Data organization is independent of any one software application. </li></ul><ul><li>Data can be organized in a manner that reduces data redundancy. </li></ul><ul><li>The DBMS can include features for: maintaining the quality of the data; handling security; and synchronizing access by simultaneous users. </li></ul><ul><li>The database system allows for capabilities such as: improved data access; allowing different views of the data for different users; and report generation. </li></ul>
  10. 10. Using SQL to Query Relational Databases <ul><li>The primary function of a database is to enable knowledge workers to obtain information from it in a usable form using queries (questions). </li></ul><ul><li>To query a relational database, many knowledge workers use Structured Query Language (SQL), which is a computer language for manipulating data in a relational database. </li></ul><ul><li>SQL queries also enable database users to add new records, or change or delete records in a database. </li></ul>
  11. 11. Important Terms <ul><li>Primary key: a field that holds a unique value for each record in a table . </li></ul><ul><li>Foreign key : the primary key from another table that is in the current table. It relates the two tables. </li></ul><ul><li>Entity: another name for a table in a relational database. </li></ul><ul><li>Row: another name for a record in a relational database table. </li></ul><ul><li>Column: another name for a field in a relational database table. </li></ul><ul><li>Query: A statement written in SQL that requests matching records, changes matching records, deletes matching records or adds new records. </li></ul>
  12. 12. Querying a Single Table Database <ul><li>To query a single table database, we use an SQL statement of the form: </li></ul><ul><li>SELECT fields FROM tables WHERE fields match query condition </li></ul><ul><li>Where the SELECT keyword designates which fields to display as a result of the query, </li></ul><ul><li>the FROM keyword designates which tables to search, and </li></ul><ul><li>the WHERE keyword specifies the search criteria, or query condition, to use in finding records. </li></ul><ul><li>Note that we use uppercase for keywords, to make them stand out, but otherwise case is not important when using SQL. </li></ul>
  13. 13. Other Query Keywords <ul><li>In addition to the SELECT keyword, there are a number of other keywords that we can use to: </li></ul><ul><ul><li>CREATE a table, </li></ul></ul><ul><ul><li>to INSERT new records in a table, </li></ul></ul><ul><ul><li>to DELETE records from a table, and </li></ul></ul><ul><ul><li>to UPDATE one or more records in a table. </li></ul></ul><ul><li>We can also search for records that are like a specific condition as well as computing sums, averages, and so on, for all records that match some criteria. </li></ul>
  14. 14. Using SQL to Display Specific Information <ul><li>The SQL to display all of the table, that is, all fields for all of the records is: </li></ul><ul><li>SELECT * FROM TableName </li></ul><ul><li>To display only a subset of the fields, the standard form of this query is (where queries can run on to the next line): </li></ul><ul><li>SELECT FieldName1, FieldName2, … FROM TableName </li></ul><ul><li>To display these records in some order, other than in increasing order of the primary key, we can add the Order By clause: </li></ul><ul><li>SELECT FieldName1, FieldName2, … FROM TableName ORDER BY FieldName </li></ul>
  15. 15. Displaying Selected Fields for Matching Records <ul><li>In many cases, we may only want to display selected fields for records that match some condition. </li></ul><ul><li>To do this, we need to use the WHERE keyword followed by some query condition involving one of six comparison operators: </li></ul><ul><ul><li>equals (=) </li></ul></ul><ul><ul><li>greater-than (>) </li></ul></ul><ul><ul><li>less-than (<) </li></ul></ul><ul><ul><li>greater-than-or-equal to (>=) </li></ul></ul><ul><ul><li>less-than-or-equal-to (<=) </li></ul></ul><ul><ul><li>not-equal-to (<>) </li></ul></ul><ul><ul><li>plus a fieldname and a value. </li></ul></ul><ul><li>The general form is: </li></ul><ul><li>SELECT FieldName1,FieldName2, … FROM TableName WHERE Query Condition </li></ul>
  16. 16. Using the LIKE Operator <ul><li>Using the equals sign in a SELECT query looks for an exact match. </li></ul><ul><li>To look for an “almost match” or to look for information about a group of products, the LIKE operator is appropriate. </li></ul><ul><li>The LIKE operator uses the wildcard character as a replacement for unknown or non-existing characters in attempting to find matches to a group of characters. </li></ul><ul><li>The wildcard character is usually either the asterisk (*) in Microsoft Access or the percent sign (%) in other database management systems. </li></ul><ul><li>The general form of this type of query is: </li></ul><ul><li>SELECT FieldName1,Fieldname2,… FROM TableName WHERE FieldName LIKE ‘*value*’ </li></ul>
  17. 17. Inserting, Deleting, or Changing Records <ul><li>To insert a record into a table, you would use an SQL statement of the form: </li></ul><ul><li>INSERT INTO TableName Values ( value1, value2, … ) </li></ul><ul><li>Note that the values must be entered in the exact order as the fields in the record, separated by commas. If there are null or missing values, the corresponding comma must be entered. </li></ul><ul><li>To delete an existing record from a database table, you would use an SQL statement of the form: </li></ul><ul><li>DELETE FROM TableName WHERE FieldName = value </li></ul><ul><li>To change values in a row of a database, you can use the UPDATE and SET keywords in the form: </li></ul><ul><li>UPDATE TableName SET FieldName1 = value WHERE FieldName2 = value </li></ul>
  18. 18. Using Aggregate Functions in SQL <ul><li>SQL can be used to compute certain values in the table using five different aggregate functions—COUNT, AVG, SUM, MIN, and MAX. </li></ul><ul><li>In each case, you must use a dummy field name for the result of the computation. </li></ul><ul><li>The form for the AVG function to find the average value of matching records is: </li></ul><ul><li>SELECT AVG(fieldname) AS DummyName FROM TableName WHERE Query condition </li></ul><ul><li>The SUM, MAX, and MIN functions have the same form as the AVG function. </li></ul><ul><li>The COUNT function to find the number of matching records uses a different form: </li></ul><ul><li>SELECT COUNT(*) AS DummyName FROM TableName WHERE Query condition </li></ul>
  19. 19. Using Logical Modeling to Create a Relational Database <ul><li>Most relational databases include many tables, not just one, to avoid redundancy . </li></ul><ul><li>This redundancy can result in the database table taking up unneeded storage space as well as causing problems when trying to insert new records, delete existing records, or update records. </li></ul><ul><li>These problems, typically referred to as anomalies, can harm the integrity of the database records. </li></ul><ul><li>To create relational databases that avoid these problems with redundancy, logical modeling is used. </li></ul><ul><li>The first step in logical modeling is to create an Entity-Relationship Diagram (ERD) that allow us to focus on the “big picture,” that is, the entities and the relationships. </li></ul>
  20. 20. Entity-Relationship Diagramming <ul><li>The symbols for an ERD are (where 1:1 means a one-to-one relationship and 1:M means a one-to-many relationship): </li></ul>
  21. 21. Example ERDs <ul><li>A one-to-many relationship with one vendor selling many products </li></ul><ul><li>A many-to-many relationship with no primary key-foreign-key relationship. Many customers buy many products. </li></ul>
  22. 22. Using a Relational Entity for M:M Relationships <ul><li>We convert an M:M relationship into two 1:M relationships by adding the PURCHASE relational entity between the CUSTOMER and the PRODUCT entities. This enables us to have the required primary and foreign keys to carry out queries. </li></ul>
  23. 23. Relational Data Models <ul><li>The next step after creating an ERD is to convert it into a corresponding relational data model. For example, the relational data model for the 1:M ERD is shown to the right. </li></ul><ul><li>Note that the relational diamond is replaced by a “crow’s foot” representing the “many” end of the relationship. </li></ul>
  24. 24. Many-to-Many Relational Models <ul><li>To model the many-to-many ERD, we add the PURCHASE entity and then use it to link the CUSTOMER and PRODUCT entities. </li></ul>
  25. 25. Complete Relational Data Model <ul><li>We can combine the two models to link all four entities into one data model. </li></ul>
  26. 26. Querying Multitable Databases <ul><li>The most common operation in querying multitable databases is the JOIN operation in which we create one table from two. </li></ul><ul><li>For example, to query the PRODUCT-VENDOR data model shown earlier, the JOIN query would be: </li></ul><ul><li>SELECT * FROM Product, Vendor WHERE Product.VendorID = Vendor.VendorID </li></ul><ul><li>This would result in a table containing all fields from both the PRODUCT and VENDOR tables where there is a match between the primary key in the VENDOR table and the foreign key in the PRODUCT table. </li></ul>
  27. 27. More Multitable Queries <ul><li>To list products, vendor name, and item cost, in alphabetical order of item name, the query is: </li></ul><ul><li>SELECT ItemName, VendorName, ItemCost FROM Product, Vendor WHERE Product.VendorID = Vendor.VendorID ORDER BY ItemName </li></ul><ul><li>To output the item name, vendor name, item cost, discount, and the net cost, the query is: </li></ul><ul><li>SELECT ItemName, VendorName, ItemCost, Discount, </li></ul><ul><li>ItemCost*(1-Discount) as NetCost FROM Product, Vendor WHERE Product.VendorID = Vendor.VendorID </li></ul><ul><li>ORDER BY ItemName </li></ul>
  28. 28. Creating Views <ul><li>In most database systems, queries can be saved and reused. </li></ul><ul><li>A saved query is often referred to as a view . </li></ul><ul><li>A query can be saved as a view and then used again by itself or as part of another query. </li></ul><ul><li>A query can be saved as a view for reasons of security. By creating a view only showing fields that we want others to see, we can protect confidential information in the data such as customer information. </li></ul>
  29. 29. Using XML <ul><li>Most companies today require the ability to share data and resources over the Web. </li></ul><ul><li>For many years companies have been using a system known as electronic data interchange (EDI) that is expensive and useful only to the very large companies. </li></ul><ul><li>With the rapid growth of the Internet, organizations have turned to the use of XML as a way of carrying out the same processes. </li></ul><ul><li>An XML file can be processed purely as data by a program, it can be stored with similar data on another computer, or, like an HTML file, it can be displayed. </li></ul>
  30. 30. Comparing XML to HTML Feature HTML XML Type of text Structured with meaning defined Formatted with meaning inferred Definition of structure User-defined Predetermined Retrieval Context-sensitive Limited Searchability Searchable by text or meaning Searchable only by text or format Hypertext linkage Extensive Limited
  31. 31. Setting Up an XML Document <ul><li>The first step to creating an XML file is to decide which tags to use to describe the data that it is transferring over the Internet. </li></ul><ul><li>As with HTML, the tags are enclosed in greater-than and less-than symbols (< >). </li></ul><ul><li>However, unlike HTML, each beginning tag must have an ending tag. For example, if using a <PARTID> tag to describe the part ID, then there must be a matching <PARTID> tag. </li></ul><ul><li>These tags must come immediately before and after the data item, to ensure that there is no ambiguity or inconsistency about the description. </li></ul><ul><li>It is a good idea to provide a formal definition of all the data elements in the XML file. This can be done in one of two ways—using the Document Type Definition method or the XML Schema method. </li></ul><ul><li>Both can be incorporated into the XML file or created as separate files with DTD or XSD extensions, respectively. </li></ul>
  32. 32. Example Schema (XSD) File (companynew.xsd)
  33. 33. Example XML File Corresponding to companynew.xsd
  34. 34. Using Stylesheet Files <ul><li>To display an XML file in a more readable form on a Web browser, we need to use an XML stylesheet (XSL) file . </li></ul><ul><li>This file uses a combination of HTML and XML tags and is itself an XML file. </li></ul>
  35. 35. Combining the Stylesheet and XML Files
  36. 36. Copyright 2008 John Wiley & Sons, Inc. All rights reserved. Reproduction or translation of this work beyond that permitted in section 117 of the 1976 United States Copyright Act without express permission of the copyright owner is unlawful. Request for further information should be addressed to the Permissions Department, John Wiley & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages caused by the use of these programs or from the use of the information herein.