Difference between revisions of "Alter & Drop"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "==Adding a Field== To add a column in a table, use the following syntax: <syntaxhighlight lang=sql> ALTER TABLE table_name ADD column_name datatype </syntaxhighlight> ==Dele...")
 
(Adding a Field)
Line 4: Line 4:
 
<syntaxhighlight lang=sql>
 
<syntaxhighlight lang=sql>
 
ALTER TABLE table_name
 
ALTER TABLE table_name
 +
ADD column_name datatype
 +
</syntaxhighlight>
 +
 +
Example:
 +
 +
<syntaxhighlight lang=sql>
 +
ALTER TABLE Persons
 
ADD column_name datatype
 
ADD column_name datatype
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 13:21, 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 column_name datatype

Deleting a Field

Next, we want to delete the column named "DateOfBirth" in the "Persons" table.

We use the following SQL statement:

ALTER TABLE Persons
DROP COLUMN DateOfBirth

Change Data Type

Now we want to change the data type of the column named "DateOfBirth" in the "Persons" table.

We use the following SQL statement:

ALTER TABLE Persons
ALTER COLUMN DateOfBirth year