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
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
The SQL Workshop
The SQL Workshop

The SQL Workshop: Learn to create, manipulate and secure data and manage relational databases with SQL

Arrow left icon
Profile Icon Frank Solomon Profile Icon Prashanth Jayaram Profile Icon Awni Al Saqqa
Arrow right icon
$17.99 $26.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8 (14 Ratings)
eBook Dec 2019 288 pages 1st Edition
eBook
$17.99 $26.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Frank Solomon Profile Icon Prashanth Jayaram Profile Icon Awni Al Saqqa
Arrow right icon
$17.99 $26.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8 (14 Ratings)
eBook Dec 2019 288 pages 1st Edition
eBook
$17.99 $26.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$17.99 $26.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

The SQL Workshop

2. Manipulating Data

Overview

This chapter teaches you to implement the INSERT, UPDATE, and DELETE statements which help you keep the content present in a table up-to-date. We will also cover how we can use default values while updating the tables.

Introduction

In Chapter 1, SQL Basics, we learned the concepts that help set up a database. Although we did insert some data into the tables, we didn't quite get into the specifics of managing the data within the database. However, there might be circumstances where we might need to change the data inserted or present in the database. For example, an employee working for a company might want to change their official number from what was updated earlier. A product that is no longer manufactured needs to be removed from the list of products available. MySQL provides some commands we can implement to make changes to the database, which will be covered in this chapter. In this chapter, we will fill the tables we created in the previous chapter with data. We will also look at the UPDATE and DELETE operations that are part of CRUD (Create, Read, Update, and Delete).

The INSERT Operation

The INSERT operation inserts a record within a table. We have already used the insert operation in the previous chapter, however, in this chapter, we are looking at it in more detail. The following are some important points about the INSERT operation:

  • It is not always essential to provide data for every single column when performing an INSERT operation. The columns can be left blank unless there is a constraint that forbids it. Some columns may even have default or system-generated values.
  • You should not alter the system-generated values.
  • The column values must match the order, data type, and size requirements.
  • The values to be inserted into the table must be enclosed in quotes in the case of strings, date-time, and characters. Numbers should not be enclosed in quotes.
  • If you do not specify the column names in the INSERT statement, your record should have a value for all the columns. Also, you should maintain the sequence of columns in...

The DELETE Operation

The DELETE statement deletes one or more rows within a table. Like the INSERT operations, DELETE also works only on a single table at a time. A deletion operation should be performed very carefully because deletion is permanent. Many database tools require you to add a WHERE clause to the DELETE FROM statement. When performing these deletion operations, which require a WHERE clause, and you would like to delete all the rows in a table, you could work around this by using a condition that is true for all the rows in the table.

For example, say you have an employee with empno 1234 who is no longer associated with the company. In such cases your query would look like the following:

DELETE FROM employees
    WHERE empno = 1234;

If you would like to remove the top 5 rows from the employees table, we would use the following query:

DELETE FROM employees
    LIMIT 5;

Exercise 2.03: Deleting a record from a table

...

The ALTER Operation

The ALTER keyword is used to make changes to the schemas present in the database. For example, if we want to add or delete columns in a table, we should be using ALTER. It can also be used rename to tables. For example:

ALTER TABLE departmentdemo RENAME TO departmentcopy;

This will rename the table departmentdemo to departmentcopy.

Now, let us look at solving one of the main issues we might encounter with auto-increment values using alter.

Exercise 2.04: Manipulating the Auto-Increment Values in a Table

In this exercise, we'll alter a table and manipulate the auto-increment values. We'll be continuing from where we left off in Exercise 2.03, Specifying Default Values. Let's go through the following steps:

  1. Delete the rows where departmentNo is greater than 2; this will delete the two rows where departmentNo is 3 and 4:
    delete from department where departmentNo>2;
  2. Select the department table to get a preview of the existing...

The UPDATE Operation

As we saw in the overview, UPDATE modifies data in one or more columns in a table. Just like the INSERT operation, the UPDATE operation can also only be performed against a single table using a single statement. In most situations, you will filter out the records you would like to update and update only them. This filtration is done using a WHERE clause in the SELECT statement. The UPDATE statement also contains a SET clause, which defines what needs to be modified within the table, along with the values.

In our demo, we'll update a table called email. You can set one column or more during an UPDATE operation. If you want to update multiple columns, separate the column names with a comma.

The database engine looks for the column that is specified in the statement and updates all the rows in it. If you would like to update only a certain row or a certain set of rows, you would use the WHERE clause. This way, you can identify only those intersections of...

Summary

In this chapter, we looked at some advanced implementations of INSERT and how we can manipulate data using the UPDATE, ALTER, and DROP commands. It is very important to remember that the ALTER command is used to update the schemas, while the update command is used to make changes in the data contained in the schemas. However, changes in the data need to managed correctly, or they will result in inconsistent data. In the next chapter, we will look at normalizing data to ensure that data integrity is maintained.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Understand the features and syntax of SQL and use them to query databases
  • Learn how to create databases and tables and manipulate the data within them
  • Create advanced queries and apply them on realistic databases with hands-on activities

Description

Many software applications are backed by powerful relational database systems, meaning that the skills to be able to maintain a SQL database and reliably retrieve data are in high demand. With its simple syntax and effective data manipulation capabilities, SQL enables you to manage relational databases with ease. The SQL Workshop will help you progress from basic to advanced-level SQL queries in order to create and manage databases successfully. This Workshop begins with an introduction to basic CRUD commands and gives you an overview of the different data types in SQL. You'll use commands for narrowing down the search results within a database and learn about data retrieval from single and multiple tables in a single query. As you advance, you'll use aggregate functions to perform calculations on a set of values, and implement process automation using stored procedures, functions, and triggers. Finally, you'll secure your database against potential threats and use access control to keep your data safe. Throughout this Workshop, you'll use your skills on a realistic database for an online shop, preparing you for solving data problems in the real world. By the end of this book, you'll have built the knowledge, skills and confidence to creatively solve real-world data problems with SQL.

Who is this book for?

This Workshop is suitable for anyone who wants to learn how to use SQL to work with databases. No prior SQL or database experience is necessary. Whether you're an aspiring software developer, database engineer, data scientist, or systems administrator, this Workshop will quickly get you up and running.

What you will learn

  • Create databases and insert data into them
  • Use SQL queries to create, read, update, and delete data
  • Maintain data integrity and consistency through normalization
  • Customize your basic SQL queries to get the desired output
  • Refine your database search using the WHERE and HAVING clauses
  • Use joins to fetch data from multiple tables and create custom reports
  • Improve web application performance by automating processes
  • Secure a database with GRANT and REVOKE privileges

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 30, 2019
Length: 288 pages
Edition : 1st
Language : English
ISBN-13 : 9781838649081
Category :
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 30, 2019
Length: 288 pages
Edition : 1st
Language : English
ISBN-13 : 9781838649081
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 139.97
The JavaScript Workshop
$43.99
The SQL Workshop
$32.99
The Python Workshop
$62.99
Total $ 139.97 Stars icon

Table of Contents

11 Chapters
1. SQL Basics Chevron down icon Chevron up icon
2. Manipulating Data Chevron down icon Chevron up icon
3. Normalization Chevron down icon Chevron up icon
4. The SELECT Statement Chevron down icon Chevron up icon
5. Shaping Data with the WHERE Clause Chevron down icon Chevron up icon
6. JOINS Chevron down icon Chevron up icon
7. Subqueries, Cases, and Views Chevron down icon Chevron up icon
8. SQL Programming Chevron down icon Chevron up icon
9. Security Chevron down icon Chevron up icon
10. Aggregate Functions Chevron down icon Chevron up icon
11. Advanced SQL Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8
(14 Ratings)
5 star 78.6%
4 star 21.4%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




D Jun 21, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I use this as a reference for my work which is very SQL heavy. I've learned a few new things and it has been a great resource to use to review materials. Definitely recommend.
Amazon Verified review Amazon
Habtish Jun 23, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I enjoyed reading the book and as I am updating myself, the book is a great summary in the area of SQL programming and very handy.
Amazon Verified review Amazon
Wm.Brutzman Jul 26, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I like this book. That this book works as a hands-on with abundant and meaningful exercises.This book is perhaps the best book for those diving-in to SQL for the first time _ and for intermediate users. The book would be a good choice for a one semester “SQL-101” course. The book is clearly written, well-written, understandable and enjoyable.Many SQL books are overly complex. This book finds the sweet spot in explaining key principles of SQL.The book well covers the fundamentals of SQL via MySQL. The book is a useful reference.A person who grasps the things in this book will be in demand _ able to land _ and keep a good job _ with many companies.Working the angles…Because find Oracle’s installation of MySQL to be challenging _ with too many advanced options _ installing the open-source _ MariaDB _ is a good alternative. MariaDB is a version of MySQL _ written by the engineers who were the original designers of MySQL. The install of MariaDB is painless.Likewise, I like using the open-source tool “Heidi SQL”. Heidi has a GUI (graphical user interface).With MariaDB and Heidi _ it is possible to work through many of the exercises _ faster.A good choice for an additional chapter in the forthcoming 2nd edition would be _ Temp Tables. I consider SQL to be “brittle” in that many examples of data are programmatically tricky. Another factor is database speed when attempting complex joins. Temp tables go a long way to simplify number crunching and grabbing only the minimum data necessary.Although there is much buzz with NoSQL databases _ I have found that the schema-less _ free-form nature of NoSQL_ is not the best choice for large projects with many tables and many programmers. Likewise, NoSQL is a challenge for newbies to grasp. MySQL is forever.Also _ there are many YouTube and other SQL video resources available. While I am a big fan of video learning _ the book The SQL WorkShop _ is a better, stronger, faster _ perhaps the best and fastest _way to get up-to-speed on SQL.
Amazon Verified review Amazon
Hemant Jun 21, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
this book will take you from beginners to advanced level to learn all the concepts of T-SQL-Siddharth Poddar
Amazon Verified review Amazon
Charles Tucker Jun 03, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
SQL is an essential tool for data analytics and data engineering, and this book does a good job of covering the basics and introducing more advanced topics. The title is fitting, as you use MySQL to gets hands-on experience with the concepts in the book.The book starts with the basics of introducing SQL, DDL, and DML, covers creating databases/tables, querying, joins, case statements, subqueries, stored procedures, built-in functions, triggers, access control, aggregate functions, and window functions.I would recommend this book to anyone who is looking to get started with SQL or has a basic knowledge and would like to become more proficient.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.