AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

SQL ALTER Table


<< Previous Page
SQL tutorial
Next Page >>
SQL tutorial

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:

ALTER TABLE your_table_name
ADD your_column_name datatype;

2. Syntax ALTER TABLE DROP column:

ALTER TABLE your_table_name
ADD your_column_name datatype;

3. Syntax ALTER TABLE - ALTER/MODIFY column:

ALTER TABLE your_table_name
ALTER COLUMN your_column_name datatype;

ALTER TABLE your_table_name
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.

Example
ALTER TABLE Users
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.

Example
ALTER TABLE Users
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:

ALTER TABLE Users DROP COLUMN Country;

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

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home - Database
SQL - Database
SQL Syntax
SQL Select Data
SQL Insert Data
SQL Update
SQL Delete Row
PHP mysqli_query()
SQL order
SQL Create Database
SQL Display Data
SQL Count()
SQL mysqli_connect
SQL create table
SQL Where And & Or
SQL like Syntax
SQL Between Operator
SQL IN Operator
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...
jQuery slideUp()...
jQuery fadeToggle...
jQuery fadeOut()...
jQuery fadeIn()...
jQuery Effects - hide () and show ()...
jQuery Events...
jQuery Attributes...
jQuery Selectors...