Advertisement: Over 100,000 Jobs Worldwide. Click here to find one for you.

MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
Send This Page to Friend
Enter Friend's Email
Enter Your Email
http://www.kareerlinks.com/jobs/skill/MySQL
 
Home / Database Structure / Tables / Question No: 73

How to add new column into an existing table in MySQL?

I want to add new column buyer_discount (integer/not null type) into my existing table buyers. How I will add this using query in MySQL?

Answer No: 73

You may use ALTER statement as follow:

ALTER TABLE `buyers` ADD `buyer_discount` INT NOT NULL;

As per above example, when you add a new column to a table, MySQL places it after all existing columns. This is the default placement unless you specify otherwise. To indicate that MySQL should place the new column in a specific position within the table, append either the keyword FIRST or the keyword-identifier combination AFTER column_name to the column definition. For example, assume that you had executed this ALTER TABLE statement instead of the previous one:

ALTER TABLE `buyers` ADD `buyer_discount` INT NOT NULL FIRST;

The FIRST keyword tells ALTER TABLE to place the new column before all existing columns (in the "first" position). Using AFTER column_name tells ALTER TABLE to place the new column after a specific existing column. For example, to place the new buyer_discount column after the existing FirstName column, you would issue this statement:

ALTER TABLE `buyers` ADD `buyer_discount` INT NOT NULL AFTER FirstName;

Comments
Submitted by JBTEIOQ on Monday, 3rd November 2008 at 21:03:27
gGUS65 <a href="http://geaxtzrvezvd.com/">geaxtzrvezvd</a>, [url=http://ogfsaclflwub.com/]ogfsaclflwub[/url], [link=http://xsqkbifdefvf.com/]xsqkbifdefvf[/link], http://yklrbftiifpt.com/

Submitted by ZNEIBYZ on Thursday, 6th November 2008 at 03:28:03
Rn2Mys <a href="http://drxkbcqjcmri.com/">drxkbcqjcmri</a>, [url=http://jgxjdmtzhlij.com/]jgxjdmtzhlij[/url], [link=http://mdnchabtzlfi.com/]mdnchabtzlfi[/link], http://lqknfrqemwdi.com/

Submitted by FNFTLBFFCLR on Tuesday, 11th November 2008 at 15:49:58
bEmb3Y <a href="http://exykbbropqek.com/">exykbbropqek</a>, [url=http://qsxffgkgiexy.com/]qsxffgkgiexy[/url], [link=http://fpgkqdsrjxzc.com/]fpgkqdsrjxzc[/link], http://crtkkffupskr.com/

Submitted by YMFBUGHM on Thursday, 13th November 2008 at 00:16:16
EliQ2K <a href="http://oyfwqylhlyhv.com/">oyfwqylhlyhv</a>, [url=http://itcgdyauoheu.com/]itcgdyauoheu[/url], [link=http://wnwmzagdzygx.com/]wnwmzagdzygx[/link], http://umcbrwjnbjoj.com/

Submitted by OHGESDOLUGT on Sunday, 16th November 2008 at 19:30:11
P1oLIf <a href="http://feezjqlgsokx.com/">feezjqlgsokx</a>, [url=http://lomjujxptlpw.com/]lomjujxptlpw[/url], [link=http://jbbmnsmzrbbh.com/]jbbmnsmzrbbh[/link], http://zxttqpiyvnba.com/

Submitted by PROPECIA on Monday, 17th November 2008 at 04:57:04
W7JDNZ Thanks for so nice site! <url>http://cfo-csuite.com/|propecia</url>

Submitted by WEIGHT-LOSS on Monday, 17th November 2008 at 05:43:09
SsWiDl Thanks for so nice site! <url>http://jintanafood.com/|weight loss pills</url>

Submitted by CIALIS on Monday, 17th November 2008 at 06:31:16
MMYrRi Thanks for so nice site! <url>http://visitweb.com/|buy cialis</url>

Submitted by GIFT-BASKET on Monday, 17th November 2008 at 08:51:42
DLdDbf Thanks for so nice site! <url>http://nifnif.org/|gift basket</url>

Submitted by POKER on Monday, 17th November 2008 at 09:40:16
deDIRX Thanks for so nice site! <url>http://winvic.net/|casino online</url>

Submitted by ABOPOULSIOLUT on Wednesday, 19th November 2008 at 04:49:00
class mates hoodia newageoptin net stop smoking seminars McNeil Consumer Healthcare [URL=http://shop-1.medsshop-online.com/Trimox/trimox.html - trimox[/URL - [URL=http://shop-1.medsshop-online.com/Lipitor/lipitor-contraindicated-for.html - lipitor contraindicated for[/URL - [URL=http://shop-1.medsshop-online.com/Viagra-Cialis/viagra-cialis-side-effects.html - viagra cialis side effects[/URL - [URL=http://shop-1.medsshop-online.com/Altace - altace[/URL - [URL=http://shop-1.medsshop-online.com/Carafate/canine-carafate.html - canine carafate[/URL - [URL=http://shop-1.medsshop-online.com/Calan/calaners.html - calaners[/URL - [URL=http://shop-1.medsshop-online.com/Alesse/birth-control-pills.html - birth control pills[/URL - [URL=http://shop-1.medsshop-online.com/Sustiva/sustiva-and-truvada.html - sustiva and truvada[/URL - [URL=http://shop-1.medsshop-online.com/Pletal/pediatric-patients.html - pediatric patients[/URL - [URL=http://shop-1.medsshop-online.com/Aciphex - aciphex[/URL - viagra cialis levitra adriamycin cytoxan alliedinterstate clomid success rates <a href=http://shop-1.medsshop-online.com/Glucosamine-Sulfate/liquid-glucosamine-sulfate.html>liquid glucosamine sulfate</a> <a href=http://shop-1.medsshop-online.com/Hyzaar/hyzaar-50-12.5.html>hyzaar 50 12.5</a> <a href=http://shop-1.medsshop-online.com/Grifulvin-V/what-is-grifulvin-v.html>what is grifulvin v</a> <a href=http://shop-1.medsshop-online.com/Metoclopramide/metoclopramide.html>metoclopramide</a> <a href=http://shop-1.medsshop-online.com/Allegra/allegra-motorhomes.html>allegra motorhomes</a> <a href=http://shop-1.medsshop-online.com/Remeron/remeron-weight-gain.html>remeron weight gain</a> <a href=http://shop-1.medsshop-online.com/Prazosin/side-effects.html>side effects</a> <a href=http://shop-1.medsshop-online.com/MSM/msm-and-hair-loss.html>msm and hair loss</a> <a href=http://shop-1.medsshop-online.com/Albendazole/missed-dose.html>missed dose</a> <a href=http://shop-1.medsshop-online.com/Lisinopril/side-effects.html>side effects</a> nimotop capsules shooting bench Zetia shoot straight http://shop-1.medsshop-online.com/Nimotop/map.html http://shop-1.medsshop-online.com/Antiox-Cats/map.html

Submitted by ACCUPRIL on Thursday, 20th November 2008 at 14:40:22
Ffx1wT Thanks you very much for that nice site! <url>http://hccpoa.cn/|order accupril</url>

Add Comments
Found a bug? Or do you have a better solution for this? Feel free to leave a message:
Leave a comment
Your Name: Your Email Address (optional):
Comment:


Related MySQL FAQs to the Above FAQ

How-to-create-table-in-MySQL How to create table in MySQL?

How-to-create-table-based-on-existing-tables How to create table based on existing tables?

What-is-temporary-table-and-how-to-create-it-in-MySQL What is temporary table and how to create it in MySQL?

How-to-describe-a-table-in-MySQL How to describe a table in MySQL?

How-to-renaming-a-table-in-MySQL How to renaming a table in MySQL?

How-to-specify-multiple-alterations-for-a-table How to specify multiple alterations for a table?

How-to-get-table-metadata How to get table metadata?

How-to-add-a-new-AUTO_INCREMENT-field-to-an-existing-table How to add a new AUTO_INCREMENT field to an existing table?

How-to-drop-a-column-from-the-existing-table How to drop a column from the existing table?

How-to-drop-all-existing-tables-in-one-go How to drop all existing tables in one go?

How-to-get-columns-of-an-existing-table-in-MySQL How to get columns of an existing table in MySQL?

How-to-change-data-type-of-an-existing-column How to change data type of an existing column?

How-to-delete-table-records How to delete table records?

How-to-set-AUTO_INCREMENT-value-other-than-1-in-MySQL How to set AUTO_INCREMENT value other than 1 in MySQL?

How-to-get-copy-of-table-structure-in-MySQL-using-query How to get copy of table structure in MySQL using query?

How-to-get-constraints-or-keys-of-the-existing-table How to get constraints or keys of the existing table?