Download presentation
Presentation is loading. Please wait.
Published byIris Hardy Modified over 9 years ago
1
Getting Started with Oracle MySQL 5.5 Community Server Edition Appendix C DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition
2
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-2
3
Appendix Objectives Learn how to create a database in MySQL 5.5 Community Server Edition Learn how to submit SQL commands to create table structures Learn how to submit SQL commands to insert database data Learn how to submit SQL commands to query a database KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-3
4
Appendix Objectives (continued) Learn how to install the MySQL OBDC/Connector Learn how to create database designs in the MySQL Workbench KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-4
5
MySQL Components 1.IMPORTANT NOTE: If you are using the Windows operating system, download and install the MySQL 5.5 Community Server Edition components only by downloading and using the MySQL Installer for Windows.MySQL Installer for Windows 2.MySQL 5.5 Community Server Edition. Download the current generally available (GA) version for your operating system.MySQL 5.5 Community Server Edition 3.MySQL Workbench. The MySQL Workbench has replaced the MySQL GUI Tools (The MySQL Query Browser and MySQL Administrator) as the graphical administration and SQL command utility for MySQL. In addition, it can be used for database design as described in Chapter 5.MySQL Workbench 4.MySQL Connector/ODBC. This provides the ODBC programs necessary to provide Web application connectivity to a MySQL database as described in Chapter 7.MySQL Connector/ODBC KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-5
6
The MySQL Workspace Folder in Windows Explorer KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-6 Figure C-1: The MySQL-Workspace Folder in Windows Explorer
7
The MySQL Workbench Home Tab KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-7 Figure C-2: The MySQL Workbench Home Tab
8
By The Way! The folks who work on the MySQL Workbench have no qualms about making major GUI changes in minor version upgrades of the product. Compare Figure 3-15 to Figure C-17 (Slide C-26 in this PowerPoint slideshow). Do you see the new, editable data row below row 12 in the query results in Figure C-17 that is not in Figure 3-15? That happened between preparing the Chapter 3 text and Appendix C text (which was finalized latter in the production process). Expect to see similar differences in the version of MySQL Workbench you download and use. The same functionality will be there, but perhaps implemented slightly differently! Be aware and be prepared! KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-8
9
The Connect to Database Dialog Box KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-9 Figure C-3: The Connect to Database Dialog Box
10
The Connect to MySQL Server Instance Dialog Box KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-10 Figure C-4: The Connect to MySQL Server Dialog Box
11
The MySQL Object Browser and SQL Query Tabbed Window KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-11 Figure C-5: The Object Browser and the SQL File Tabbed Window
12
The Create Schema Button KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-12 Figure C-6: The new_schema Tabbed Window
13
Naming the New Database KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-13 Figure C-7: The WPC Schema Name in the new_schema Dialog Box
14
The Apply SQL Script to Database — Review SQL Script Dialog Box KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-14 Figure C-8: The Apply SQL Script to Database – Review SQL Script Dialog Box
15
The Apply SQL Script to Database — Apply SQL Script Dialog Box KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-15 Figure C-9: The Apply SQL Script to Database—Apply SQL Script Dialog Box
16
The New Database (Schema) in the Object Browser KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-16 Figure C-10: The wpc Schema (Database) in the Object Browser
17
The Set as Default Schema Command KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-17 Figure C-11: The Set as Default Schema Command
18
WPC as the Active Schema (Default Schema) KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-18 Figure C-12: The WPC Schema as the Active Schema (Default Schema)Command
19
AUTO_INCREMENT KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall MySQL uses the AUTO_INCREMENT keyword to set surrogate key values. The default values for AUTO_INCREMENT are an initial value of 1 and an increment of 1. After the table is created, you can modify the initial value by using the ALTER TABLE statement. For example, in the WPC database, the PROJECT table has a surrogate key that starts at 1000 and increments by 100. You could set the correct initial value by using the SQL statement: ALTER TABLE PROJECT AUTO_INCREMENT=1000; Unfortunately, you cannot change the MySQL increment of 1. So for cases such as the ProjectID values in PROJECT, you need to manually insert the correct values in MySQL. C-19
20
The WPC Database Table SQL Statements for MySQL I KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-20 Figure C-13: The WPC Database Table SQL Statements for MySQL
21
The WPC Database Table SQL Statements for MySQL II KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-21 Figure C-13: The WPC Database Table SQL Statements for MySQL (cont’d)
22
The WPC Database Table SQL Statements for MySQL III KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-22 Figure C-13: The WPC Database Table SQL Statements for MySQL (cont’d)
23
The WPC SQL Script in the MySQL Workbench KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-23 Figure C-14: The WPC Script in the MySQL Workbench
24
The WPC SQL Script Results in the MySQL Workbench KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-24 Figure C-15: The SQL Script Results
25
The WPC SQL INSERT Statements for PROJECT KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall MySQL expects dates to be entered using a very specific format: 'YYYY-MM-DD' Note how this format is used in the SQL INSERT INTO PROJECT commands below: C-25 Figure C-16: The WPC Database Data INSERT Statements for MySQL
26
An SQL Query and Query Results in the MySQL Workbench KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-26 Figure C-17: The SQL Query and Results in the MySQL Workbench
27
The MySQL Connector/ODBC KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall IMPORTANT NOTE: If you are using the Windows operating system, download and install the MySQL Connector/ODBC component only by downloading and using the MySQL Installer for Windows.MySQL Installer for Windows For non-Windows operating systems, the MySQL Connector/ODBC must be installed as a separate installation for the other MySQL components. Download the MySQL Connector/ODBC form the MySQL Website at http://dev.mysql.com/downloads/connector/odbc/.http://dev.mysql.com/downloads/connector/odbc/ Run the installation routine. As soon as the install is complete, the MySQL ODBC 5.1 Driver will be available in the ODBC Data Source Administrator. C-27
28
The MySQL Workbench Data Modeling Area KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-28 Figure C-1: The MySQL Workbench Home Tab
29
Creating Database Designs in the MySQL Workbench KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall To create a new data model in the MySQL Workbench, you can: Use the File | New Model command, or Click the Create new EER Model link on the Home page. C-29
30
The MySQL Model Tab and Window KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-30 Figure C-18: The MySQL Model Tab and Window
31
The Blank E-R Diagram KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-31 Figure C-19: The Blank E-R Diagram
32
Placing the Table Object KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-32 Figure C-20: Placing the Table Object
33
The table1 Table Object KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-33 Figure C-21: The table1 Table Object
34
The MySQL Table Editor KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-34 Figure C-22: The MySQL Table Editor
35
The Renamed Table KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-35 Figure C-23: The Renamed Table
36
MySQL Workbench Table Column Checkbox Options KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall PK Primary Key—Check if this column is the primary key or part of a composite primary key. NN NOT NULL—Check if this column must have an inserted value. UQ UNIQUE—Check if this column must contain a unique value. BIN Binary—Check if this the column uses only two values, such as 0 and 1 or Yes and No. UN Unsigned Data Type—Check if this column uses numbers without negative values and you specifically want to not permit negative numbers where they might otherwise be allowed. Zero fill (ZF) numbers are automatically check UN. ZF Zero Fill—Check if this column should be automatically filled with zeros. AI AUTO_INCREMENT—Check if this column is a primary key that should have sequential surrogate key values C-36
37
The Generated Primary Key idDEPARTMENT KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-37 Figure C-24: The MySQL Table Editor Generated Primary Key idDEPARTMENT
38
The Datatype Drop-Down List KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-38 Figure C-25: The Datatype Drop-Down List
39
The Completed DepartmentName Primary Key Column KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-39 Figure C-26: The Completed DepartmentName Primary Key Column
40
The Completed DEPARTMENT Table KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-40 Figure C-27: The Completed DEPARTMENT Table
41
The Completed DEPARTMENT, EMPLOYEE and PROJECT Tables KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-41 Figure C-28: The Completed DEPARTMENT, EMPLOYEE and PROJECT Tables
42
Relationships in the MySQL Workbench EER Diagram Toolbar KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-42 Figure C-29: Relationships in the MySQL Workbench EER Diagram Toolbar
43
MySQL Workbench Relationship Button Options KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1:1 Nonidentifying Relationship—Used between two strong entities. 1:N Nonidentifying Relationship—Used between two strong entities. 1:1 Identifying Relationship—Used between a strong entity and an ID-dependent weak entity—BUT an identifying relationship requires multiple children, so this does not make sense! 1:N Identifying Relationship—Used between a strong entity and an ID-dependent weak entity. N:M Identifying Relationship— Used between a strong entity and an ID-dependent weak entity—BUT because a N:M relationship is between two strong entities, this should be nondentifying! HOWEVER, it is immediately converted to two 1:N ID-dependent identifying relationships as discussed below. Place a Relationship Using Existing Columns—See discussion below. C-43
44
By the Way The usage of 1:1 nonidentifying, 1:N nonidentifying, and 1:N identifying relationships are standard and correct. However, by definition an identifying relationship has to be used in a 1:N relationship (see Chapter 4), so the 1:1 identifying relationship does not make sense. Similarly, pure N:M relationships only exist in data models, and they are always nonidentifying relationships between two strong entities, so this symbol should use a dashed line instead of a solid one. KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-44
45
By the Way The MySQL Workbench uses the term non- identifying relationship, whereas in Database Concepts we use the term nonidentifying relationship. We have seen the term non identifying relationship used in other contexts. All three terms mean exactly the same thing, and which is used is a matter of style. As MySQL Workbench uses non-identifying, we will also use that term in this appendix for consistency with the MySQL Workbench screen shots, while remaining well aware that we have used nonidentfying in Database Concepts itself. KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-45
46
Place a Relationship Using Existing Columns The Foreign Key Columns Dialog Box – Pick Columns for Foreign Key KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-46 Figure C-30: The Foreign Key Columns Dialog Box—Pick Columns for Foreign Key
47
Place a Relationship Using Existing Columns EMPLOYEE.Department Selected as The Foreign Key Column KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-47 Figure C-31: EMPLOYEE.Department Selected As the Foreign Key Column
48
Place a Relationship Using Existing Columns The Referenced Columns Dialog Box – Pick Referenced Primary Key KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-48 Figure C-32: The Referenced Columns Dialog Box—Pick Referenced Primary Key
49
Place a Relationship Using Existing Columns The Completed 1:N Non-identifying Relationship KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-49 Figure C-33: The Completed 1:N Non-identifying Relationship
50
Place a Relationship Using Existing Columns The fk_EMPLOYEE_DEPARTMENT Foreign Key Properties KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-50 Figure C-34: The fk_EMPLOYEE_DEPARTMENT Foreign Key Properties
51
The Completed DEPARTMENT, EMPLOYEE and PROJECT Relationships KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-51 Figure C-35: The Completed DEPARTMENT, EMPLOYEE and PROJECT Relationships
52
MySQL Workbench N:M Relationships KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall An N:M relationship only exists in a data model (as a non-identifying relationship between two strong entities. In a database design, the N:M relationship becomes two 1:N ID-dependent identifying relationships linking the two original tables through a new, third table called an intersection table. MySQL Workbench only builds database designs and automatically creates the intersection table with the two 1:N relationships whenever we specify an N:M relationship. C-52
53
The Completed Set of Relationships KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-53 Figure C-36: The Completed Set of Relationships
54
The Completed E-R Diagram KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall C-54 Figure C-37: The Completed E-R Diagram
55
Getting Started with Oracle MySQL 5.5 Community Server Edition End of Presentation on Appendix C DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.