Alter table add column | MODIFY COLUMN SYNTAX IN SQL - sql - sql tutorial - learn sql
- The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
- The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
- The SQL Server (Transact-SQL) ALTER TABLE can use the ALTER TABLE statement in SQL Server to add a column to a table.
- Add multiple columns in table.
- Modify column in table.
- Drop column in table.
- Rename column in table and etc.
- For Oracle and MySQL, the SQL syntax for ALTER TABLE Modify Column is,
ALTER TABLE "table_name"
MODIFY "column_name" "New Data Type";
- For SQL Server, the syntax is,
ALTER TABLE "table_name"
ALTER COLUMN "column_name" "New Data Type";
- Let's look at the example. Assuming our starting point is the Customer table created in the CREATE TABLE section:
Table Wikitechy_Customer
| Column Name | Data Type |
|---|---|
| First_Name | char(50) |
| Last_Name | char(50) |
| Address | char(50) |
| City | char(50) |
| Country | char(25) |
| Birth_Date | datetime |
- Our goal is to alter the data type of the "Address" column to char(100). To do this, we key in:
MySQL:
ALTER TABLE Wikitechy_Customer MODIFY Address char(100);
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorialOracle:
Oracle:
ALTER TABLE Wikitechy_Customer MODIFY Address char(100);
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorialSQL Server:
SQL Server:
ALTER TABLE Wikitechy_Customer ALTER COLUMN Address char(100);
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorialResulting table structure:
Resulting table structure:
Table Wikitechy_Customer
| Column Name | Data Type |
|---|---|
| First_Name | char(50) |
| Last_Name | char(50) |
| Address | char(100) |
| City | char(50) |
| Country | char(25) |
| Birth_Date | datetime |