More about maintaining a table - speaker notes
This presentation will deal with INSERT, UPDATE and DELETE as well as CREATE and DESCRIBE.
Review of creating a table.
If you do not remember the structure used when you created the table, issue the DESCRIBE command followed by the table name to see the structure.
Note that DESCRIBE can also be entered as DESC.
Remember that character data - VARCHAR2 and CHAR as well as DATE data are enclosed in single quotes. Numeric data is not enclosed in single quotes.
If the column/field names are not listed after the table name, it is assumed that data will go into all of the fields.
UPDATE can be used to change existing data or add data to null columns/fields.dat
This UPDATE commands updates two columns/fields for the row/record where the stuidno = 3333.
In this slide, I inserted a record into the table and then showed the file with the inserted record.
Then, using the DELETE FROM, I deleted the record and showed the results.
ALTER TABLE allows you to change the structure of a table.
In this example, I used ADD.
As can be seen in this example, I added a column/field called STU_OPT.
When I do a DESCRIBE of the table you can see the addition and when I SELECT all of the data you can see a blank column on each row/record.
The UPDATE is now used to update the new column that was created with the ALTER.
Let's say I decided that stu_opt was too small. I can modify the structure using ALTER TABLE followed by MODIFY.
Now that I have changed stu_opt from 5 characters to 10 characters, I can change the data in the column as shown with this update.
This slide shows an error result from trying to decrease a column/field size that contains data. Data would have been lost if the ALTER had been allowed.
All records will end up with a GPA of 4.