Difference between revisions of "Alter & Drop"
Line 16: | Line 16: | ||
==Deleting a Field== | ==Deleting a Field== | ||
− | + | To delete the column named "DateOfBirth" in the "Persons" table you could use the following SQL statement: | |
− | |||
− | |||
<syntaxhighlight lang=sql> | <syntaxhighlight lang=sql> | ||
Line 27: | Line 25: | ||
==Change Data Type== | ==Change Data Type== | ||
− | + | To change the data type of the column named "DateOfBirth" in the "Persons" table you could use the following SQL statement: | |
− | |||
<syntaxhighlight lang=sql> | <syntaxhighlight lang=sql> | ||
ALTER TABLE Persons | ALTER TABLE Persons | ||
ALTER COLUMN DateOfBirth year | ALTER COLUMN DateOfBirth year | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 13:23, 24 December 2016
Adding a Field
To add a column in a table, use the following syntax:
ALTER TABLE table_name
ADD column_name datatype
Example:
ALTER TABLE Persons
ADD DateOfBirth date
Deleting a Field
To delete the column named "DateOfBirth" in the "Persons" table you could use the following SQL statement:
ALTER TABLE Persons
DROP COLUMN DateOfBirth
Change Data Type
To change the data type of the column named "DateOfBirth" in the "Persons" table you could use the following SQL statement:
ALTER TABLE Persons
ALTER COLUMN DateOfBirth year