Copyright

SQL: UPDATE Statement

Instructor: Marcia Wert

Marcia has taught Information technology and Mathematics with a master's degree in IT

The SQL update statement allows us to manipulate data in a relational database. It is a powerful statement that lets us make multiple changes simultaneously. In this lesson, we'll learn the syntax for this command and also look at an example of it in use.

What is SQL?

SQL or Structured Query Language is a special language used only in relational databases. It allows us to manipulate databases called relational databases, which are electronic tables that are organized around a key or keys for fast access and inquiry. The update clause is a special query that will allow changes to be made based on conditions specified.

It is formatted like this:


UPDATE table
SET column1 = expression,
column2 = expression2,
[WHERE conditions];
OR
UPDATE table1
SET column1 = (SELECT expression
FROM table2
WHERE conditions 2);


Note that we can specify different conditions and the WHERE clause is optional. The latter stipulates conditions that must be met in order for the update to take place. Omitting it can produce varying update changes, however.

We use the 'SET' to specify new values.

Given the following table Flight, let's take a scenario where your flight has had its time changed. For the sake of convenience only a portion of the table Flights will be shown.

Flights (original table)

Departing_Airport Arriving_Airport Flight_Number Depart_Time AM/PM
OHR LAX 145 7:45 AM
OHR LAX 699 9:00 PM
LAX ATL 725 10:00 PM
OHR ATL 525 10:30 PM

If your flight number 699 has an hour delay to update the table, we would code:


UPDATE Flights
SET Depart_Time = '10:00'
WHERE Flight_Number = 699;


The resulting table would look like this:

Flights (new table)

Departing_Airport Arriving_Airport Flight_Number Depart_Time AM/PM
OHR LAX 145 7:45 AM
OHR LAX 699 10:00 PM
LAX ATL 725 10:00 PM
OHR ATL 525 10:30 PM

Let's now take a look at the other format that you might employ with UPDATE.

Here are two tables, Flights and Airport_Names:

Airport_Names

Name Abbrevation
Los Angelos LAX
O'Hare OHR
Atlanta ATL

Flights (original table)

Departing_Airport Arriving_Airport Flight_Number Depart_Time AM/PM
OHR LAX 145 7:45 AM
OHR LAX 699 9:00 PM
LAX ATL 725 10:00 PM
OHR ATL 525 10:30 PM


To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support