View Single Post
  #3 (permalink)  
Old 03-05-2007, 11:21 PM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: Adding a new Column in middle of the Table

Mr.vadivelanvaidyanathan,

In Mysql

I mean to say that if we have created a table with the defined structure.

Now i want to add one more field to that table, if am adding a new field that
will be added as the last field in the table.

For Ex:

I want to store the Employee Id,Name and Designation.
My Table Structure is,

CREATE TABLE EMP
(
EMP_ID INTEGER AUTO_INCREMENT COMMENT'Primary Key',
EMP_NAME VARCHAR(100) NOT NULL COMMENT'Employee Name',
EMP_DESIGNATION VARCHAR(100) NOT NULL COMMENT'Employee Designation',
EMP_ACTIVE INTEGER DEFAULT 1 NOT NULL COMMENT'1- Working Currently,Suspended Temporarly,Left the Office',
PRIMARY KEY(EMP_ID)
);


Now i want to include the Employee salary with Name and Designation.
Then

ALTER TABLE EMP ADD EMP_SAL INTEGER NOT NULL;

Now the new added field will be added as the last field in the table,i.e

EMP_ID
EMP_NAME
EMP_DESIGNATION
EMP_ACTIVE
EMP_SAL - New Added Field

But i wish to add the field in order,Employee Salary must be next to the Designation Field, Then the Syntax is,

ALTER TABLE EMP ADD EMP_SAL INTEGER NOT NULL AFTER EMP_DESIGNATION;

Now the Order of the Field will be as follows,

EMP_ID
EMP_NAME
EMP_DESIGNATION
EMP_SAL - New Added Field
EMP_ACTIVE

Its Clear.....
__________________
-Murali..
Reply With Quote