SQL ALTER Table
SQL Tutorial » CREATE Table
What is alter table in SQL?
ALTER TABLE statement in SQL is used to add, delete, or modify columns in an existing table, but is also used to add and drop various constraints on an existing table
1. Syntax ALTER TABLE ADD column:
ADD your_column_name datatype;
2. Syntax ALTER TABLE DROP column:
ADD your_column_name datatype;
3. Syntax ALTER TABLE - ALTER/MODIFY column:
ALTER COLUMN your_column_name datatype;
MODIFY COLUMN your_column_name datatype;
Let's look at the "Users" table: We will have four columns as: "id", "first_name", "last_name" and "country".
ID | First Name | Last Name | Country |
---|---|---|---|
1 | Clark | Kent | USA |
2 | Pire | Joveau | France |
3 | Nicky | Anderson | USA |
4 | Pepe | Martínez | Spain |
5 | Peter | Parker | SUA |
SQL ALTER TABLE ADD column Example
Now using ALTER TABLE we want to add a column named "Date_Of_Birth" in the "Users" table.
ADD Date_Of_Birth date;
The table "Users" it will look like that:
ID | First Name | Last Name | Country | Date_Of_Birth |
---|---|---|---|---|
1 | Clark | Kent | USA | |
2 | Pire | Joveau | France | |
3 | Nicky | Anderson | USA | |
4 | Pepe | Martínez | Spain | |
5 | Peter | Parker | SUA |
Related subjects:
SQL DROP DataBase
SQL update DataBase
PHP select / view data
Conect to MySQLi
SQL insert into table
Tags: SQL ALTER Table: and foreign key, add cokumn, add multiple columns, primary key, add constraint, delete column, change column name, add column with default, create index, rebame column, modify column
Can we alter table in SQL?
What is altering table in SQL?
How do I edit a table in SQL query?
Change Data Type Example
Now we want to change the data type of the column named "Date_Of_Birth" in the "Users" table.
ALTER COLUMN Date_Of_Birth year;
"Date_Of_Birth" column is now type year will be in a two or four digits format.
ALTER TABLE DROP COLUMN
The following SQL deletes the "Country" column from the "Users" table:
The result:
ID | First Name | Last Name | Date_Of_Birth |
---|---|---|---|
1 | Clark | Kent | |
2 | Pire | Joveau | |
3 | Nicky | Anderson | |
4 | Pepe | Martínez | |
5 | Peter | Parker |
SQL ALTER Table: and foreign key, add cokumn, add multiple columns, primary key, add constraint, delete column, change column name, add column with default, create index, rebame column, modify column
Can we alter table in SQL?
What is altering table in SQL?
How do I edit a table in SQL query?
SQL ALTER Table - sql tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.