Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learn SQL using MySQL in One Day and Learn It Well
Learn SQL using MySQL in One Day and Learn It Well

Learn SQL using MySQL in One Day and Learn It Well: SQL for beginners with Hands-on Project

By Jamie Chan
€14.99 per month
Book Apr 2024 121 pages 1st Edition
eBook
€7.99 €4.99
Subscription
€14.99 Monthly
eBook
€7.99 €4.99
Subscription
€14.99 Monthly

What do you get with a Packt Subscription?

Free for first 7 days. $15.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details


Publication date : Apr 26, 2024
Length 121 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781836205678
Category :
Table of content icon View table of contents Preview book icon Preview Book

Learn SQL using MySQL in One Day and Learn It Well

Chapter 1: Introduction

 

Welcome to SQL and thank you so much for picking up my book. I sincerely hope that this book can help you master SQL fast and introduce you to the exciting world of databases.

 

This book adopts a hands-on approach to learning. As we progress from one chapter to another, we’ll be doing various exercises. You are strongly encouraged to follow along these exercises.

 

At the end of the book, we’ll also be working on a new project together. This project involves building a SQL database for a sports complex. We’ll learn to build the database, insert data, perform queries, write routines, views, cursors, and more.

 

Excited and ready to start embarking on our SQL learning journey? Let’s do it!

 

What is SQL?

 

Simply stated, SQL stands for Structured Query Language and is a language used to manage data stored in a relational database.

This brings us to the next question - What is a database?

 

A database is a collection of data organized in some format so that the data can be easily accessed, managed and updated. The predominant type of database is a relational database. Relational databases organize data in the form of tables. In addition, they contain queries, views and other elements to help us interact with the data.

 

In order to manage our database, we need to use a software application known as a database management system (DBMS).

 

Clear?

 

So far, we have the following terminologies:

 

1) SQL is a language
2) A database is a structured collection of data
3) A DBMS is a software that we use to manage our databases

 

With regards to DBMS, there are a large number of them available. Some are free to download and use while others are not. The most commonly used DBMS include MySQL, Oracle, Microsoft SQL Server and IBM DB2.

 

Each of these DBMS have their own versions of SQL. While this may sound intimidating, rest assured that all DBMS support the major SQL commands (such as SELECT, UPDATE, DELETE, INSERT) in a similar manner. Hence, if you know one version of SQL, it is very easy to pick up other versions.

 

In this book, we'll be using MySQL. This is one of the most popular DBMS available. Best of all, it’s free! From this point forward, whenever I mention SQL, I’m referring to the MySQL version.

 

Getting Ready to Code

 

In order to start using MySQL, we need to first download and install two applications: MySQL Server and My SQL Workbench.

 

Note that the instructions provided below are accurate as of March 2024. MySQL may update its download links or alter installation procedures in the future. In such cases, you can typically find the most up-to-date installation guides on YouTube by searching for terms like "Installing MySQL on Windows" or "Installing MySQL on Mac" and selecting the latest video with the highest number of views.

 

For the time being, let's proceed with installing the latest version of MySQL.

 

Installing MySQL applications

 

Windows

 

For Windows users, go to https://dev.mysql.com/downloads/installer/.

 

Image

 

Scroll down and click on the second “Download” button to download the application. You’ll be directed to another page. Scroll to the bottom of the page and click on “No thanks, just start my download.”

 

Once you have downloaded the program, double-click on the file and follow the instructions to install the software. When prompted for administrative permissions, click “Yes” to grant the necessary permissions.

 

Next, you will be prompted to choose a setup type, select “Custom” and click “Next”.

 

Image

 

You’ll be asked to select the products to install.

 

Image

 

Under “Available Products”, fully expand “MySQL Servers” by clicking on the + signs. Once fully expanded, select the latest version (currently 8.0.36) and click on the green arrow to move this item to the “Products To Be Installed” section.

 

Next, scroll down and expand “Applications”. Fully expand “MySQL Workbench”, select the latest version, and click on the green arrow to move this item to the “Products To Be Installed” section.

 

Once you are done, click on “Next” and follow the instructions to continue with the installation. Stick to the default options selected at each stage.

 

When prompted to enter a password (MySQL Root Password), enter your desired password and jot down the password; you’ll need this password later.

 

Click on “Next” to continue and complete the installation.

 

Mac OS

 

For Mac users, to install MySQL Server, go to https://dev.mysql.com/downloads/mysql/.

 

Scroll down and click on the first “Download” button if your system uses an Apple silicon processor (such as the M1 or M2 chip) or the second “Download” button if it uses an Intel processor.

 

Image

 

Once you do that, you’ll be directed to another page. Scroll to the bottom of the page and click on “No thanks, just start my download.”

 

Once you have downloaded the program, double-click on the file and follow the instructions to install the software. If you are asked for permission to continue, click on “Allow”, “Agree”, or provide your Macbook password when prompted to proceed.

 

At the configuration stage, choose “Use Strong Password Encryption” and click “Next”. Enter your desired password and jot down the password; you’ll need this password later. Ensure that the "Start MySQL Server once the installation is complete" option is selected and click on "Finish" to complete the installation.

 

Once you are done installing MySQL Server, you need to install another software known as MySQL Workbench. This software provides us with a graphical user interface to make it easier for us to interact with MySQL. To download MySQL Workbench, go to https://dev.mysql.com/downloads/workbench/.

 

Click on the appropriate “Download” button (depending on the processor that your Macbook uses) to download the application. Once again, you’ll be directed to another page. Scroll to the bottom of the page and click on “No thanks, just start my download.” to download the program. Double-click on the downloaded file and follow the instructions to install it after downloading.

 

Launching MySQL Workbench

 

Once you have installed the necessary applications, we are ready to do some coding.

 

First, launch MySQL Workbench, you’ll get the screen below:

 

Image

 

Click on the grey rectangle under "MySQL Connections" and you’ll be prompted for a password. Enter the password that you keyed in previously when you installed MySQL Server and select “Save password in vault” (or “Save password in keychain” for Mac users). Next, press OK to proceed. If all goes well, you should be directed to a screen that looks like the one below:

 

Image

 

The main area is a text editor where we’ll be entering our SQL commands. The window below is the output area (refer to the screenshot above).

 

There’s an additional panel on the right (labeled “SQLAdditions” in the screenshot above) that we do not need. You can close this panel by selecting View > Panels > Hide Secondary Sidebar in the top menu.

Writing our first MySQL code

 

Now, we are ready to get our feet wet and write some SQL code.

 

Type the following lines into the text editor (for the first line, be sure to add a space after the two hyphens):

 

-- Using SELECT to display messages

SELECT 'Hello World';

SELECT 'MySQL is fun!';

 

You should notice that the word SELECT is in blue and 'Hello World' and 'MySQL is fun!' are in brown. (The colors may differ depending on your settings or the MySQL Workbench version that you are using).

 

This is the software’s way of making our code easier to read. Different words serve different purposes in our program, hence they are displayed using different colors. We’ll go into more detail in later chapters.

 

There are two ways to run the SQL commands that we wrote.

 

The first task is to select all the code that we want to run and click on the "Execute Selected" button (the button with a lightning bolt icon).

 

This button should normally be located to the right of the "Save" button (refer to the previous screenshot); it executes the selected portion of the script, or everything if there is no selection.

 

You will see a new panel called "Result Grid," with two tabs as shown below:

 

Image

 

These two tabs give the results of the last two lines of code that we wrote (i.e. the two lines that start with the word SELECT).

 

The first line of code that we wrote does not give any result as it is a comment. We’ll talk about comments in the next section.

 

Besides running all the code at one go, you can also choose to execute them one by one. To do that, simply position your cursor on the line that you want to execute and click on the “Execute Statement” button to run that statement. The “Execute Statement” button shows a lightning bolt and a cursor and is located to the right of the “Execute Selected” button.

 

For instance, if you place your cursor as shown in the image below

 

Image

 

and click on the “Execute Statement” button, you’ll get a single tab in the “Result Grid” that displays the message Hello World.

 

Comments

 

Now that we know how to execute SQL statements, we are ready to start learning some SQL commands. However, before we do that, there’s one more concept that I’ll like to cover - comments.

 

As mentioned previously, the first line in the code that we wrote (-- Using SELECT to display messages) is a comment.

 

Comments are written to make our code more readable for other programmers. They are meant for humans only and are ignored by the DBMS.

 

To add comments to our program, we type two hyphens, followed by a space, as demonstrated in the example above.

 

Alternatively, we can also use the # symbol as shown below:

 

# This is another way to add comment

 

Last, but not least, if we want to type multiple lines comments, we can use the /*...*/ symbols:

 

/* This is a comment

This is also a comment

This is the third comment */

Left arrow icon Right arrow icon

Key benefits

  • Step-by-step guidance from basic to advanced SQL techniques
  • Comprehensive coverage of MySQL, a leading database management system
  • Practical exercises with solutions to reinforce learning

Description

Learn SQL (using MySQL) in One Day and Learn It Well is the ultimate guide for beginners aiming to grasp the complexities of SQL through hands-on learning. Starting with an introduction to the essence of databases, this book methodically advances through defining and manipulating tables, mastering data insertion, updates, deletions, and executing sophisticated data selection techniques across its comprehensive chapters. It further explores the creation and utility of views, the implementation of triggers to automate database responses, and the intricacies of variables, stored routines, control flow tools, and cursors, culminating in a capstone project that brings all concepts together. Culminating in a project , this book offers a unique opportunity to apply all the learned concepts in a practical, real-world scenario, reinforcing the skills and knowledge acquired throughout the chapters. The appendices provide additional resources including table definitions for practical exercises modeled on real-world scenarios. Embark on a learning journey that transitions you from novice to proficient in managing and querying databases with MySQL, empowering you with the skills to tackle real-world data challenges.

What you will learn

Understand the fundamental concepts and architecture of databases Define and design efficient database tables to store data logically Utilize advanced selection techniques to manipulate & analyze data Create views to simplify complex queries and enhance accessibility Implement triggers to automate database operations Complete a hands-on project to apply skills in a practical scenario

What do you get with a Packt Subscription?

Free for first 7 days. $15.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details


Publication date : Apr 26, 2024
Length 121 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781836205678
Category :

Table of Contents

16 Chapters
Chapter 1: Introduction Chevron down icon Chevron up icon
Chapter 2: Defining the Database Chevron down icon Chevron up icon
Chapter 3: Defining Tables Chevron down icon Chevron up icon
Chapter 4: Inserting, Updating and Deleting Data Chevron down icon Chevron up icon
Chapter 5: Selecting Data Part 1 Chevron down icon Chevron up icon
Chapter 6: Selecting Data Part 2 Chevron down icon Chevron up icon
Chapter 7: Selecting Data Part 3 Chevron down icon Chevron up icon
Chapter 8: Views Chevron down icon Chevron up icon
Chapter 9: Triggers Chevron down icon Chevron up icon
Chapter 10: Variables and Stored Routines Chevron down icon Chevron up icon
Chapter 11: Control Flow Tools Chevron down icon Chevron up icon
Chapter 12: Cursors Chevron down icon Chevron up icon
Chapter 13: Project Chevron down icon Chevron up icon
Appendix A: Tables for companyHR Chevron down icon Chevron up icon
Appendix B: Tables for sportsDB Chevron down icon Chevron up icon
Appendix C: Suggested Solution for Project Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.