Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The MySQL Workshop

You're reading from   The MySQL Workshop A practical guide to working with data and managing databases with MySQL

Arrow left icon
Product type Paperback
Published in Apr 2022
Publisher Packt
ISBN-13 9781839214905
Length 726 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Scott Cosentino Scott Cosentino
Author Profile Icon Scott Cosentino
Scott Cosentino
Thomas Pettit Thomas Pettit
Author Profile Icon Thomas Pettit
Thomas Pettit
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Section 1: Creating Your Database
2. Chapter 1: Background Concepts FREE CHAPTER 3. Chapter 2: Creating a Database 4. Chapter 3: Using SQL to Work with a Database 5. Chapter 4: Selecting, Aggregating, and Applying Functions 6. Section 2: Managing Your Database
7. Chapter 5: Correlating Data across Tables 8. Chapter 6: Stored Procedures and Other Objects 9. Chapter 7: Creating Database Clients in Node.js 10. Chapter 8: Working with Data Using Node.js 11. Section 3: Querying Your Database
12. Chapter 9: Microsoft Access – Part 1 13. Chapter 10: Microsoft Access – Part 2 14. Chapter 11: MS Excel VBA and MySQL – Part 1 15. Chapter 12: Working With Microsoft Excel VBA – Part 2 16. Section 4: Protecting Your Database
17. Chapter 13: Getting Data into MySQL 18. Chapter 14: Manipulating User Permissions 19. Chapter 15: Logical Backups 20. Other Books You May Enjoy Appendix

Exercise 1.01: Organizing data in a relational format

Suppose you are working for a company, ABC Corp. Your manager would like to develop a database that stores clients' contact information, as well as the orders a client has made. You have been asked to determine how to organize the data in a relational format. In addition, the company would like you to define the data types that are appropriate for each field. The following is a list of properties that are to be stored in the relational model:

  • Customer Data:
    • Customer ID
    • Customer Name
    • Customer Address
    • Customer Phone Number
  • Order Data:
    • Customer ID
    • Order ID
    • Order Price

Perform the following steps to create a relational database structure:

  1. First, determine the data types that are appropriate for the data. The ID fields should be int data type, since IDs are typically numeric. For fields containing names, addresses, and phone numbers, a varchar data type is appropriate since it can store general text. Finally, a price can be defined as double, since it needs to be able to store decimal values.
  2. Determine how many tables you should have. In this case, you have two sets of data, which means you should have two tables – CustomerData and OrderData.
  3. Consider how tables are related to each other. Since a customer can have an order in the order data, you can conclude that customers and orders are related to one another.
  4. Next, look at what columns are the same between the two sets of data. In this case, both tables contain the CustomerID column.

Finally, combine all the information. You have two tables, CustomerData and OrderData. You can relate them by using the column they share, which is CustomerID. The relational model would look like the following:

Figure 1.6 – The data for customers and orders organized in a relational format

Figure 1.6 – The data for customers and orders organized in a relational format

With this, you now have a fully defined relational structure for your data. This structure with data types can be used to construct a proper relational database.

Now, you will delve into the architecture of MySQL in the following section.

You have been reading a chapter from
The MySQL Workshop
Published in: Apr 2022
Publisher: Packt
ISBN-13: 9781839214905
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image