Interactive SQL Tutorial
10. Adding, deleting, updating data
Adding Data
To insert rows into a table, do the following:
INSERT INTO ANTIQUES VALUES (21,
01, 'Ottoman', 200.00)
This inserts the data into the table, as a new row, column-by-column,
in the pre-defined order. Instead, let's change the order and leave
Price blank:
INSERT INTO ANTIQUES (BUYERID,
SELLERID, ITEM)
VALUES (01, 21, 'Ottoman')
Deleting Data
Let's delete this new row back out of the database:
DELETE FROM ANTIQUES
WHERE ITEM = 'Ottoman'
But if there is another row that contains 'Ottoman', that row will be
deleted also. Let's delete all rows (one, in this case) that contain
the specific data we added before:
DELETE FROM ANTIQUES
WHERE ITEM = 'Ottoman' AND BUYERID
= 01 AND SELLERID = 21
Updating Data
Let's update a Price into a row that doesn't have a price listed yet:
UPDATE ANTIQUES SET PRICE = 500.00
WHERE ITEM = 'Chair'
This sets all Chair's Prices to 500.00. As shown above, more WHERE
conditionals, using AND, must be used to limit the updating to more
specific rows. Also, additional columns may be set by separating
equal statements with commas.
<< Prev
1
2
3
4
5
6
7
8
9
10
11
12
13
Next >>
|