MySQL Alter
MySQL Alter
Command
Alter Command
The SQL ALTER TABLE command is used
to change the structure of an existing
table.
It helps to add or delete columns, create
or destroy indexes, change the type of
existing columns, or rename columns or
the table itself.
It can also be used to change the
comment for the table and type of the
table.
Alter Command - Syntax
alter command is used for alteration of
table structures and various uses
of alter command are
to add a column to existing table
to rename any existing column
to change data type of any column or
to modify its size
alter is also used to drop a column
Alter Clause Query Renaming a Table
show tables;
Show columns
from tutorial;
Alter Clause Query Adding a Column to an Existing
Table
Write a SQL statement to add a column tutReview
after tutorial_title to the table tutorial
ALTER TABLE tutorial
ADD tutReview VARCHAR(30) AFTER tutorial_title
Alter Clause Query Drop a Column from an Existing
Table
Write a SQL statement to drop the column
tutReview from the table tutorial
ALTER TABLE tutorial
DROP tutReview
Alter Clause Query Modify the Data Type of a
Column from an Existing Table
Write a SQL statement to change the data type of
the column tutorial_id to varchar in the table
tutorial
ALTER TABLE tutorial
MODIFY tutorial_id VARCHAR(4)
<?php
$db="TUTORIALS";
$link = mysqli_connect('localhost', 'root', '');
if (! $link)
die(mysqli_error($link));
mysqli_select_db( $link,$db) or die("Select Error:
".mysqli_error($link));