Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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
$32.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8 (14 Ratings)
Paperback Dec 2019 288 pages 1st Edition
eBook
$9.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
$32.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8 (14 Ratings)
Paperback Dec 2019 288 pages 1st Edition
eBook
$9.99 $26.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $26.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

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 : 9781838642358
Category :
Languages :
Concepts :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Dec 30, 2019
Length: 288 pages
Edition : 1st
Language : English
ISBN-13 : 9781838642358
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
Banner background image

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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela