Updating and deleting data

A database very rarely stays the same once it been created - data is added, deleted and sometime changed.

Updating data

To change existing data the update SQL statement is used.

An example of an update statement would be:

1
2
3
UPDATE Product
SET Name=?, Price=?
WHERE ProductID=?

This statement would enable you to alter the name and price of an existing product.

The video below demonstrates how to use this statement:


Task 5

Use the above video to create an update statement and then amend some of your product data.


Deleting data

Being able to delete data from the database is another important function that must be learned. To delete existing data the delete from SQL statement is used.

An example of a delete statement would be:

1
2
DELETE FROM Product
WHERE ProductID=?

This statement would remove all data associated with the ProductID, including its name and price.

The video below demonstrates how to use this statement:


Task 6

Use the above video to create a delete statement and then delete some of your product data.


Searching and Sorting

Now that we have discovered how to create a database structure and manage the data within it we can turn our attention to one of the major benefits of databases - being able to easily search and sort data.