You are writing commnad statements based on the table shown below, as well as ot
ID: 3656580 • Letter: Y
Question
You are writing commnad statements based on the table shown below, as well as other tables in the General Hardware Company database. Use standard SQL syntax for the commands unless otherwise specified.
(d)PRODUCT table
PRODNUMPRODNAME UNITPRICE
16386 Wrench 12.95
19440 Hammer 17.50
21765 Drill 32.99
24013 Saw 26.25
26722 Pilers 11.50
1. You want to change the price of the hammer listed in the table to 18.01. Show two ways you could do this.
(d)PRODUCT table
PRODNUMPRODNAME UNITPRICE
16386 Wrench 12.95
19440 Hammer 17.50
21765 Drill 32.99
24013 Saw 26.25
26722 Pilers 11.50
Explanation / Answer
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
To add a column in a table, use the following syntax:
To delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a column):
To change the data type of a column in a table, use the following syntax:
SQL Server / MS Access:
My SQL / Oracle:
Look at the "Persons" table:
Now we want to add a column named "DateOfBirth" in the "Persons" table.
We use the following SQL statement:
Notice that the new column, "DateOfBirth", is of type date and is going to hold a date. The data type specifies what type of data the column can hold. For a complete reference of all the data types available in MS Access, MySQL, and SQL Server, go to our complete Data Types reference.
The "Persons" table will now like this:
P_Id LastName FirstName Address City 1 Hansen Ola Timoteivn 10 Sandnes 2 Svendson Tove Borgvn 23 Sandnes 3 Pettersen Kari Storgt 20 StavangerRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.