SQL ALTER TABLE Add Column Syntax


  SQL > Table Manipulation > Alter Table Add Column Syntax

The SQL syntax for ALTER TABLE Add Column is

ALTER TABLE "table_name"
ADD "column 1" "Data Type"

Let's look at the example. Assuming our starting point is the "customer" table created in the CREATE TABLE section:

Table customer
Column NameData Type
First_Namechar(50)
Last_Namechar(50)
Addresschar(50)
Citychar(50)
Countrychar(25)
Birth_Datedate

Our goal is to add a column called "Gender". To do this, we key in:

MySQL:
ALTER TABLE customer ADD Gender char(1);

Oracle:
ALTER TABLE customer ADD Gender char(1);

SQL Server:
ALTER TABLE customer ADD Gender char(1);

Resulting table structure:

Table customer
Column NameData Type
First_Namechar(50)
Last_Namechar(50)
Addresschar(50)
Citychar(50)
Countrychar(25)
Birth_Datedate
Genderchar(1)

Note that the new column Gender becomes the last column in the customer table.

It is also possible to add multiple columns. For example, if we want to add a column called "Email" and another column called "Telephone", we will type the following:

MySQL:
ALTER TABLE customer ADD (Email char(30), Telephone char(20));

Oracle:
ALTER TABLE customer ADD (Email char(30), Telephone char(20));

SQL Server:
ALTER TABLE customer ADD (Email char(30), Telephone char(20));

The table now becomes:

Table customer
Column NameData Type
First_Namechar(50)
Last_Namechar(50)
Addresschar(50)
Citychar(50)
Countrychar(25)
Birth_Datedate
Genderchar(1)
Emailchar(30)
Telephonechar(20)

ALTER TABLE MODIFY COLUMN >>

Link to this page: If you find this page useful, we encourage you to link to this page. Simply copy and paste the code below to your website, blog, or profile.



Copyright 2010 1keydata.com.   All Rights Reserved.     Privacy Policy  








SQL SELECT
SQL DISTINCT
SQL WHERE
SQL AND OR
SQL IN
SQL BETWEEN
SQL Wildcard
SQL LIKE
SQL ORDER BY
SQL Functions
SQL Average
SQL COUNT
SQL MAX
SQL MIN
SQL SUM
SQL GROUP BY
SQL HAVING
SQL ALIAS
SQL AS
SQL JOIN
SQL OUTER JOIN
SQL SELECT UNIQUE
SQL CONCATENATE
SQL SUBSTRING
SQL TRIM
SQL LENGTH
SQL REPLACE
SQL DATEADD
SQL DATEDIFF
SQL DATEPART
SQL GETDATE
SQL SYSDATE

SQL CREATE TABLE
SQL CONSTRAINT
SQL NOT NULL
SQL DEFAULT
SQL UNIQUE
SQL CHECK
SQL PRIMARY KEY
SQL FOREIGN KEY
SQL View
SQL CREATE VIEW
SQL Index
SQL CREATE INDEX
SQL ALTER TABLE
SQL DROP TABLE
SQL TRUNCATE TABLE
SQL USE
SQL INSERT INTO
SQL UPDATE
SQL DELETE FROM

SQL Jobs

Site Map
Resources



CSS Tutorial

PHP Tutorial

Data Warehousing & Business Intelligence