MBA 7020 Business Analysis Foundations Data Warehousing & Data Mining  July 25, 2005
Agenda Data Mining Designing & Building the Data Warehouse Appendix: SQL Data Warehouse & Relational Database
The Data Warehouse <ul><li>The Data Warehouse </li></ul><ul><li>is physically separated from all other operational systems...
Data Flow Operational Data Store Data Warehouse Data Mart Metadata Legacy Systems Personal Data Warehouse
Metadata <ul><li>What is Metadata? </li></ul><ul><li>Data about Data </li></ul><ul><li>Without metadata, the data is meani...
Data Warehouse Vendors <ul><li>Business Objects </li></ul><ul><li>Cognos </li></ul><ul><li>Hyperion </li></ul><ul><li>IBM ...
Relational Database   A relational  database  is a collection of  data  items organized as a set of formally-described tab...
Relational Database   When creating a relational database, you can define the domain of possible values in a data column a...
Business Intelligence Environment   Internal Source Systems External Data Sources Extract, Transformation and Load Data Wa...
Relational Database <ul><li>IBM DB2, DB2/400 </li></ul><ul><li>Microsoft SQL/Server </li></ul><ul><li>Teradata </li></ul><...
SQL <ul><li>SQL – Structured Query Language </li></ul><ul><li>DDL – Data Definition Language </li></ul><ul><li>Create </li...
Relational Database RDBMS Software Application SQL Request Result Set
Agenda Data Mining Designing & Building the Data Warehouse Appendix: SQL Data Warehouse & Relational Database
  Why Business Intelligence <ul><li>Improve consistency and accuracy of reporting </li></ul><ul><li>Reduce stress on opera...
  ERM vs. DM <ul><li>ERM - Entity Relationship Model </li></ul><ul><ul><li>Remove redundancy </li></ul></ul><ul><ul><li>Ef...
  Dimensional Model
  Retail Sales Dimensional Model (Partial)
  Fact Table <ul><li>Contains Foreign Keys that relate to Dimension Tables </li></ul><ul><li>Have a many-to-one relationsh...
  Dimension Table <ul><li>Contains a Primary Key that relates to the Fact Table(s) </li></ul><ul><li>Has a one-to-many rel...
Agenda Data Mining Designing & Building the Data Warehouse Appendix: SQL What is Data Mining? Market Basket Analysis Marke...
What is Data Mining? <ul><li>A set of activities used to find new, hidden, or unexpected patterns in data </li></ul><ul><l...
OLAP – Online Analytical Processing <ul><li>MOLAP – Multidimensional OLAP </li></ul><ul><li>ROLAP – Relational OLAP </li><...
Limitations of Data Mining <ul><li>All relevant data items / attributes may not be collected by the operational systems </...
Techniques and Technologies <ul><li>Techniques Used to Mine the Data </li></ul><ul><ul><li>Classification </li></ul></ul><...
General Data Mining Methods <ul><li>Predicting which customers will purchase, based on demographics, psychographics, firmo...
Analytics Process DISCOVERY DATA  PREPARATION KNOWLEDGE  DEVELOPMENT LEVERAGING  ANALYTICS POST  ANALYSIS OPPORTUNITIES ID...
Market Basket Analysis <ul><li>Market Basket Analysis </li></ul><ul><ul><li>Most common and useful in Marketing </li></ul>...
Market Basket Analysis <ul><li>Association Rules for Market Basket Analysis </li></ul><ul><li>All associations are unidire...
Market Basket Analysis <ul><li>3 Measures of Market Basket Analysis  </li></ul><ul><li>Support – the percentage of baskets...
Market Basket Analysis <ul><li>Market Basket Analysis results can be: </li></ul><ul><li>Trivial  </li></ul><ul><ul><li>Hot...
Marketing Analytics Landscape Where can I find new customers? Where can I find more revenue & profit from my current custo...
Direct Marketing Campaign Platform
Cluster Analysis <ul><li>Definition: The identification and grouping of consumers that share similar characteristics </li>...
Cluster Analysis <ul><li>Only want a small subset of variables for clustering </li></ul><ul><li>Weed out undesirable varia...
Clustering Prospect Base Midscale / Leisure Traveler Upscale / Leisure Traveler Country Club / Resort Set Midscale / Busin...
  Cluster Analysis   Attribute Cluster Name A B C D E (ALL) Age of Head of Household   38   62   48   44   52   43 Length ...
  Cluster Analysis  
  Cluster Analysis   Cluster 1 Cluster 1 Cluster 1 ------------ Calculate Scores (ROI, Response, Utilization) Overlay Prof...
Agenda Data Mining Appendix: SQL Designing & Building the Data Warehouse Data Warehouse & Relational Database
SQL Select Statement SELECT column1, column2, . . . FROM table1, table2, . . . WHERE criteria1 AND/OR criteria2 . . . . . ...
  SQL Select Statement SELECT column1, column2, . . . FROM table1, table2, . . . WHERE criteria1 AND/OR criteria2 . . . . ...
  SQL – Example 1 SQL CREATE  TABLE ADDR_BOOK ( NAME char(30),  COMPANY char(20),  E_MAIL char (25)  Output Name Company E...
  SQL – Example 2 2a) SQL SELECT  NAME,  COMPANY, E_MAIL  FROM  ADDR_BOOK  WHERE COMPANY = ‘Microsoft'  Output Name Compan...
  SQL – Example 3 SQL SELECT  ADDR_BOOK.NAME,  COMPANY.EMAIL FROM  ADDR_BOOK,  COMPANY  WHERE ADDR_BOOK.EMPLOYEE_ID = COMP...
  SQL – Example 4 SQL CREATE TABLE CUSTOMER (  CUST_NO INTEGER,  FIRST_NAME CHAR(30),  LAST_NAME CHAR(30),  ADDRESS CHAR(5...
  SQL – Example 5 SQL CREATE  TABLE ADDR_BOOK ( NAME char(30),  COMPANY char(20),  E_MAIL char (25)  Output Name Company E...
  SQL – Example 6 – Referential Integrity SQL CREATE TABLE CUSTOMER (  CUST_NO INTEGER PRIMARY KEY,  FIRST_NAME CHAR(30), ...
  SQL – Example 7 – Index When you have a primary key, you already have an implicitly (or explicitly) defined unique index...
Upcoming SlideShare
Loading in …5
×

Data Warehousing

470
-1

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
470
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Data Warehousing

  1. 1. MBA 7020 Business Analysis Foundations Data Warehousing & Data Mining July 25, 2005
  2. 2. Agenda Data Mining Designing & Building the Data Warehouse Appendix: SQL Data Warehouse & Relational Database
  3. 3. The Data Warehouse <ul><li>The Data Warehouse </li></ul><ul><li>is physically separated from all other operational systems </li></ul><ul><li>holds aggregated data and transactional data for management separate from that data used for online transaction processing </li></ul>
  4. 4. Data Flow Operational Data Store Data Warehouse Data Mart Metadata Legacy Systems Personal Data Warehouse
  5. 5. Metadata <ul><li>What is Metadata? </li></ul><ul><li>Data about Data </li></ul><ul><li>Without metadata, the data is meaningless </li></ul><ul><li>Provides consistency of the truth </li></ul><ul><li>Components of Metadata </li></ul><ul><li>Transformation Mapping </li></ul><ul><li>Extraction and Relationship History </li></ul><ul><li>Algorithms for Summarization (and calculations) </li></ul><ul><li>Data Ownership </li></ul><ul><li>Patterns of Warehouse Access </li></ul><ul><li>Business Friendly naming conventions </li></ul><ul><li>Status Information </li></ul>
  6. 6. Data Warehouse Vendors <ul><li>Business Objects </li></ul><ul><li>Cognos </li></ul><ul><li>Hyperion </li></ul><ul><li>IBM </li></ul><ul><li>Microsoft </li></ul><ul><li>NCR / Teradata </li></ul><ul><li>Oracle </li></ul><ul><li>SAS </li></ul>
  7. 7. Relational Database A relational database is a collection of data items organized as a set of formally-described tables from which data can be accessed or reassembled in many different ways without having to reorganize the database tables. The relational database was invented by E. F. Codd at IBM in 1970. The standard user and application program interface to a relational database is the structured query language ( SQL ). SQL statements are used both for interactive queries for information from a relational database and for gathering data for reports. A relational database is a set of tables containing data fitted into predefined categories. Each table (which is sometimes called a relation ) contains one or more data categories in columns. Each row contains a unique instance of data for the categories defined by the columns. For example, a typical business order entry database would include a table that described a customer with columns for name, address, phone number, and so forth. Another table would describe an order: product, customer, date, sales price, and so forth. A user of the database could obtain a view of the database that fitted the user's needs. For example, a branch office manager might like a view or report on all customers that had bought products after a certain date. A financial services manager in the same company could, from the same tables, obtain a report on accounts that needed to be paid.
  8. 8. Relational Database When creating a relational database, you can define the domain of possible values in a data column and further constraints that may apply to that data value. For example, a domain of possible customers could allow up to ten possible customer names but be constrained in one table to allowing only three of these customer names to be specifiable. The definition of a relational database results in a table of metadata or formal descriptions of the tables, columns, domains, and constraints. Meta is a prefix that in most information technology usages means &quot;an underlying definition or description.&quot; Thus, metadata is a definition or description of data and metalanguage is a definition or description of language. A database is a collection of data that is organized so that its contents can easily be accessed, managed, and updated. The most prevalent type of database is the relational database , a tabular database in which data is defined so that it can be reorganized and accessed in a number of different ways. A distributed database is one that can be dispersed or replicated among different points in a network. An object-oriented programming database is one that is congruent with the data defined in object classes and subclasses. SQL (Structured Query Language) is a standard interactive and programming language for getting information from and updating a database . Although SQL is both an ANSI and an ISO standard, many database products support SQL with proprietary extensions to the standard language. Queries take the form of a command language that lets you select, insert, update, find out the location of data, and so forth.
  9. 9. Business Intelligence Environment Internal Source Systems External Data Sources Extract, Transformation and Load Data Warehouse Data Mart
  10. 10. Relational Database <ul><li>IBM DB2, DB2/400 </li></ul><ul><li>Microsoft SQL/Server </li></ul><ul><li>Teradata </li></ul><ul><li>Oracle </li></ul><ul><li>Sybase </li></ul><ul><li>Informix / Red Brick </li></ul><ul><li>Microsoft Access </li></ul><ul><li>MySQL </li></ul>
  11. 11. SQL <ul><li>SQL – Structured Query Language </li></ul><ul><li>DDL – Data Definition Language </li></ul><ul><li>Create </li></ul><ul><li>Drop </li></ul><ul><li>Alter </li></ul><ul><li>DML – Data Manipulation Language </li></ul><ul><li>Insert </li></ul><ul><li>Update </li></ul><ul><li>Delete </li></ul><ul><li>Select </li></ul>
  12. 12. Relational Database RDBMS Software Application SQL Request Result Set
  13. 13. Agenda Data Mining Designing & Building the Data Warehouse Appendix: SQL Data Warehouse & Relational Database
  14. 14. Why Business Intelligence <ul><li>Improve consistency and accuracy of reporting </li></ul><ul><li>Reduce stress on operational systems for reporting and analysis </li></ul><ul><li>Faster access to information </li></ul><ul><li>BI tools provide increased analytical capabilities </li></ul><ul><li>Empowering the Business User </li></ul><ul><li>Companies are realizing that data is a company’s most underutilized asset </li></ul>
  15. 15. ERM vs. DM <ul><li>ERM - Entity Relationship Model </li></ul><ul><ul><li>Remove redundancy </li></ul></ul><ul><ul><li>Efficiency of transactions </li></ul></ul><ul><li>DM - Dimensional Model </li></ul><ul><ul><li>Intuitive View of the Data </li></ul></ul><ul><ul><li>Efficiency of access and analysis </li></ul></ul>
  16. 16. Dimensional Model
  17. 17. Retail Sales Dimensional Model (Partial)
  18. 18. Fact Table <ul><li>Contains Foreign Keys that relate to Dimension Tables </li></ul><ul><li>Have a many-to-one relationship to Dimension Tables </li></ul><ul><li>Contains Metrics to be aggregated </li></ul><ul><li>Typically does not contain any non-foreign key or non-metric data elements </li></ul><ul><li>Level of Granularity defines depth and flexibility of analysis </li></ul>
  19. 19. Dimension Table <ul><li>Contains a Primary Key that relates to the Fact Table(s) </li></ul><ul><li>Has a one-to-many relationship to the Fact Table(s) </li></ul><ul><li>Contains Descriptive data used to limit and aggregated metrics from the Fact Table(s) </li></ul><ul><li>Can sometimes contain pre-aggregated data </li></ul>
  20. 20. Agenda Data Mining Designing & Building the Data Warehouse Appendix: SQL What is Data Mining? Market Basket Analysis Marketing Analytics – Direct Marketing Campaign Cluster Analysis Data Warehouse & Relational Database
  21. 21. What is Data Mining? <ul><li>A set of activities used to find new, hidden, or unexpected patterns in data </li></ul><ul><li>Verification versus Discovery </li></ul><ul><li>Accuracy in predicting consumer behavior </li></ul>
  22. 22. OLAP – Online Analytical Processing <ul><li>MOLAP – Multidimensional OLAP </li></ul><ul><li>ROLAP – Relational OLAP </li></ul>Data Warehouse / Data Mart RDBMS
  23. 23. Limitations of Data Mining <ul><li>All relevant data items / attributes may not be collected by the operational systems </li></ul><ul><li>Data noise or missing values (data quality) </li></ul><ul><li>Large database requirements and multi-dimensionality </li></ul>
  24. 24. Techniques and Technologies <ul><li>Techniques Used to Mine the Data </li></ul><ul><ul><li>Classification </li></ul></ul><ul><ul><li>Association </li></ul></ul><ul><ul><li>Sequence </li></ul></ul><ul><ul><li>Cluster </li></ul></ul><ul><li>Data Mining Technologies </li></ul><ul><ul><li>Statistical Analysis </li></ul></ul><ul><ul><li>Neural Networks, Genetic Algorithms and Fuzzy Logic </li></ul></ul><ul><ul><li>Decision Trees </li></ul></ul>
  25. 25. General Data Mining Methods <ul><li>Predicting which customers will purchase, based on demographics, psychographics, firmographics, service history, transactions, credit history, etc. Statistical algorithms and decision trees are used for these problems with much success. </li></ul><ul><li>Market Basket Analysis: which customers who purchase an additional telephone line are also likely to purchase dialup internet service? Pattern matching works well: associative rules, fuzzy logic, neural networks. </li></ul><ul><li>Which types of activities precede each other; eg, do customer hospitality and gaming activities show patterns or sequences? We use a combination of statistical modeling and simulations to identify these trigger points for action, and to estimate the marginal value of each. </li></ul><ul><li>Clustering is useful for determining similar groups based on how closely they resemble each other. Multitude of clustering techniques exist, with the primary difference being in how they define what is “close”. Clustering can be very useful for marketing messaging and advertising, strategy development and implementation, and channel development. </li></ul>Classification: Association: Sequencing: Clustering:
  26. 26. Analytics Process DISCOVERY DATA PREPARATION KNOWLEDGE DEVELOPMENT LEVERAGING ANALYTICS POST ANALYSIS OPPORTUNITIES IDENTIFYING SCOPING OBJECTIVE SETTING DATA WAREHOUSE EXTERNAL DATA APPEND DATA EXTRACTION DATA VALIDATION STATISTICAL MODELING SEGMENTATION OFFER OPTIMIZATION CUSTOMER BEHAVIOR SCORING DIRECT MAIL TELEMARKETING EMAIL LOYALTY CAMPAIGN RESULTS DECOMPOSITION REFINING ANALYTICS FEEDBACK HYPOTHESIS TESTING DEVELOPING HYPOTHESES EFFORT FEEDBACK FOR
  27. 27. Market Basket Analysis <ul><li>Market Basket Analysis </li></ul><ul><ul><li>Most common and useful in Marketing </li></ul></ul><ul><ul><li>What products customers purchase together </li></ul></ul><ul><ul><ul><li>Diapers and Beer sell well on Thursday nights </li></ul></ul></ul><ul><li>Benefits </li></ul><ul><ul><li>Better target marketing </li></ul></ul><ul><ul><li>Product positioning with stores (virtual stores) </li></ul></ul><ul><ul><li>Inventory management </li></ul></ul><ul><li>Limitations </li></ul><ul><ul><li>Large volume of real transactions needed </li></ul></ul><ul><ul><li>Difficult to correlate frequently purchased items with infrequently purchased items </li></ul></ul><ul><ul><li>Results of previous transactions could have been affected by other marketing promotions </li></ul></ul>
  28. 28. Market Basket Analysis <ul><li>Association Rules for Market Basket Analysis </li></ul><ul><li>All associations are unidirectional and take on the following form: </li></ul><ul><ul><li>Left-hand side rule IMPLIES Right-hand side rule </li></ul></ul><ul><ul><li>Left and Right hand side can both contain multiple items (Multi-dimensional Market Analysis) </li></ul></ul><ul><ul><li>Examples: </li></ul></ul><ul><ul><ul><li>Steak IMPLIES Red Wine </li></ul></ul></ul><ul><ul><ul><li>Hunting Magazines IMPLIES Smokeless Tobacco </li></ul></ul></ul>
  29. 29. Market Basket Analysis <ul><li>3 Measures of Market Basket Analysis </li></ul><ul><li>Support – the percentage of baskets in the analysis where the rule is true </li></ul><ul><ul><li>Of 100 baskets 11 contained both steaks and red wine. </li></ul></ul><ul><ul><li>11% support </li></ul></ul><ul><li>Confidence – the percentage of Left-hand side items that also have right-side items </li></ul><ul><ul><li>Of the 17 baskets that contained steak, 11 contained red wine. </li></ul></ul><ul><ul><li>65% confidence </li></ul></ul><ul><li>Lift – compares the likelihood of finding the right-hand item in any random basket </li></ul><ul><ul><li>Also referred to as Improvement </li></ul></ul><ul><ul><li>Lift of less than 1 means it is less predictive than random choice </li></ul></ul><ul><ul><li>If Confidence is 35%, but the right-hand side items is in 40% of the baskets, the rule offers no Improvement of random selection. </li></ul></ul>
  30. 30. Market Basket Analysis <ul><li>Market Basket Analysis results can be: </li></ul><ul><li>Trivial </li></ul><ul><ul><li>Hot Dogs IMPLIES Hot Dog Buns </li></ul></ul><ul><ul><li>TV IMPLIES TV Warranty </li></ul></ul><ul><li>Inexplicable </li></ul><ul><li>Virtual Items – Associating non-items or other attributes into the correlation study </li></ul><ul><li>“ New Customer” </li></ul>
  31. 31. Marketing Analytics Landscape Where can I find new customers? Where can I find more revenue & profit from my current customers? Which of my customers are at risk and how can I keep them? Which customers do I want to win back? Strategy & Tactics: Guiding the business & helping to make numbers Business Planning, Forecasting, Corp Strategy, Financial Metrics, Profitability Analysis Customer Knowledge – Who are my customers? Segmentation & Profiles, External Data, Mkt Share/Wallet Share, Channel Preference Modeling <ul><li>Customer Acquisition </li></ul><ul><li>Prospect profiling </li></ul><ul><li>Event driven marketing </li></ul><ul><li>Propensity to buy & response modeling </li></ul><ul><li>Marketing Optimization </li></ul><ul><li>Market Basket Analysis </li></ul><ul><li>Online and Retail Channels </li></ul><ul><li>Customer and product churn modeling </li></ul><ul><li>Retentive stickiness of key products </li></ul><ul><li>Prediction of key events (eg, residential movers) </li></ul><ul><li>Customer reacquisition </li></ul><ul><li>Customer profitability analysis </li></ul>Acquisition Growth Reacquisition Retention
  32. 32. Direct Marketing Campaign Platform
  33. 33. Cluster Analysis <ul><li>Definition: The identification and grouping of consumers that share similar characteristics </li></ul><ul><li>Yields: better understanding of prospects/customers </li></ul><ul><li>Translates into: improved business results through revised strategies attributes </li></ul><ul><li>Definition: The identification and grouping of consumers that share similar characteristics </li></ul><ul><li>Process: </li></ul><ul><ul><li>Data Selection </li></ul></ul><ul><ul><li>Missing Values </li></ul></ul><ul><ul><li>Standardization </li></ul></ul><ul><ul><li>Removal of Outliers </li></ul></ul><ul><ul><li>Cluster Analysis Considerations </li></ul></ul>
  34. 34. Cluster Analysis <ul><li>Only want a small subset of variables for clustering </li></ul><ul><li>Weed out undesirable variables </li></ul><ul><ul><li>Can use PROC FACTOR, PROC CORR </li></ul></ul><ul><ul><li>Can use expert system </li></ul></ul><ul><li>Consideration for observations, weighting </li></ul><ul><li>Probably done with factor analysis </li></ul><ul><li>If not, then two options </li></ul><ul><ul><li>Set Missing to Mean of data </li></ul></ul><ul><ul><li>Set Missing to Value of Equivalent Performance </li></ul></ul><ul><li>No right or wrong answer </li></ul><ul><li>Might do both - depending on variables </li></ul>
  35. 35. Clustering Prospect Base Midscale / Leisure Traveler Upscale / Leisure Traveler Country Club / Resort Set Midscale / Business Traveler Upscale / Business Traveler – Prosperous Traveler Other Upscale / Business Traveler – Loan Dependent
  36. 36. Cluster Analysis   Attribute Cluster Name A B C D E (ALL) Age of Head of Household   38   62   48   44   52   43 Length of Residence in high income group zip codes   7   12   9   6   7   7 Household Income (,000)   48   45   102   73   71   72 Weekday Check in   13   1   3   6   2   3 Weekend Check in   69   6   29   51   7   30 No. Stays (resort) between Jan 1, 2001 and Jun 30, 2002   0   5   6   5   3   2 No. Stays (mid properties) between Jan 1, 2001 and Jun 30, 2002   11   55   21   15   32   16 No. Stays (upscale properties) between Jan 1, 2001 and Jun 30, 2002   24   2   10   15   8   7
  37. 37. Cluster Analysis  
  38. 38. Cluster Analysis   Cluster 1 Cluster 1 Cluster 1 ------------ Calculate Scores (ROI, Response, Utilization) Overlay Profitability Estimate Evaluate Risk-Return Tradeoff (by Offer and by Cluster) Make Final Selections DM/Offer 1 DM /Offer 2 DM /Offer N -------- Low RETURN High Low RISK High Mail No-Mail
  39. 39. Agenda Data Mining Appendix: SQL Designing & Building the Data Warehouse Data Warehouse & Relational Database
  40. 40. SQL Select Statement SELECT column1, column2, . . . FROM table1, table2, . . . WHERE criteria1 AND/OR criteria2 . . . . . ORDER BY column1, column1, . . .
  41. 41. SQL Select Statement SELECT column1, column2, . . . FROM table1, table2, . . . WHERE criteria1 AND/OR criteria2 . . . . . ORDER BY column1, column1, . . . GROUP BY column1, column1, . . . HAVING criteria1 AND/OR criteria2 . . . . . Aggregation
  42. 42. SQL – Example 1 SQL CREATE TABLE ADDR_BOOK ( NAME char(30), COMPANY char(20), E_MAIL char (25) Output Name Company Email John Smith Microsoft [email_address] Jeff Jones Delta [email_address]
  43. 43. SQL – Example 2 2a) SQL SELECT NAME, COMPANY, E_MAIL FROM ADDR_BOOK WHERE COMPANY = ‘Microsoft' Output Name Company Email John Smith Microsoft [email_address] 2b) Table - Product ID Name Category I Internet A B Browsers A A Application Null G Graphics Null SQL SELECT ID, NAME from PRODUCT WHERE CATEGORY = NULL
  44. 44. SQL – Example 3 SQL SELECT ADDR_BOOK.NAME, COMPANY.EMAIL FROM ADDR_BOOK, COMPANY WHERE ADDR_BOOK.EMPLOYEE_ID = COMPANY.EMPLOYEE_ID Output Name Email John Smith [email_address] Jeff Jones [email_address]
  45. 45. SQL – Example 4 SQL CREATE TABLE CUSTOMER ( CUST_NO INTEGER, FIRST_NAME CHAR(30), LAST_NAME CHAR(30), ADDRESS CHAR(50), CITY CHAR(30), STATE CHAR (2), ZIP_CODE CHAR(9), COUNTRY CHAR(20) ) CREATE TABLE ORDER ( ORDER_NO INTEGER, DATE_ENTERED DATE, CUST_NO INTEGER ) SQL SELECT ORDER.ORDER_NO, CUSTOMER.NAME, CUSTOMER.ADDRESS, CUSTOMER.CITY, CUSTOMER.ZIP_CIDE, CUSTOMER.COUNTRY FROM ORDER, CUSTOMER WHERE ORDER.CUST_NO = CUSTOMER.CUST_NO AND ORDER.DATE_ENTERED = '1998-20-11'
  46. 46. SQL – Example 5 SQL CREATE TABLE ADDR_BOOK ( NAME char(30), COMPANY char(20), E_MAIL char (25) Output Name Company Email John Smith Microsoft [email_address] Jeff Jones Delta [email_address]
  47. 47. SQL – Example 6 – Referential Integrity SQL CREATE TABLE CUSTOMER ( CUST_NO INTEGER PRIMARY KEY, FIRST_NAME CHAR(30), LAST_NAME CHAR(30), ADDRESS CHAR(50), CITY CHAR(30), ZIP_CODE CHAR(9), COUNTRY CHAR(20) ) CREATE TABLE ORDER ( ORDER_NO INTEGER PRIMARY KEY, DATE_ENTERED DATE, CUST_NO INTEGER REFERENCES CUSTOMER (CUST_NO) ) SQL CREATE TABLE ORDER_ITEMS ( ORDER_NO INTEGER, ITEM_NO INTEGER, PRODUCT CHAR(30), QUANTITY INTEGER, UNIT_PRICE MONEY ) ALTER TABLE ORDER_ITEMS ADD PRIMARY KEY PK_ORDER_ITEMS (ORDER_NO, ITEM_NO) ALTER TABLE ORDER_ITEMS ADD FOREIGN KEY FK_ORDER_ITEMS_1 (ORDER_NO) REFERENCES ORDER (ORDER_NO)
  48. 48. SQL – Example 7 – Index When you have a primary key, you already have an implicitly (or explicitly) defined unique index on the primary key columns. It's generally a good idea to define non-unique indexes on the foreign keys. SQL CREATE UNIQUE INDEX PK_CUSTOMER ON CUSTOMER (CUST_NO) CREATE UNIQUE INDEX PK_ORDER ON ORDER (ORDER_NO) CREATE INDEX FK_ORDER_1 ON ORDER (CUST_NO) CREATE UNIQUE INDEX PK_ORDER_ITEMS ON ORDER_ITEMS (ORDER_NO, ITEM_NO) CREATE INDEX FK_ORDER_ITEMS_1 ON ORDER_ITEMS (ORDER_NO)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×