IT Community - Software Programming, Web Development and Technical Support

Adding a new Column in middle of the Table

This is a discussion on Adding a new Column in middle of the Table within the Database Support forums, part of the Web Development category; Hi Friends, MYSQL Just want to share the Concept of Adding a New Field in the Middle of the Table ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-04-2007, 11:23 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 Adding a new Column in middle of the Table

Hi Friends,

MYSQL

Just want to share the Concept of Adding a New Field in the Middle of the Table

CREATE TABLE IF NOT EXISTS test
(
id INTEGER AUTO_INCREMENT,
name VARCHAR(100),
PRIMARY KEY(id)
);

Now i want to add a field between id and name in the table.

ALTER TABLE test ADD emp_id INTEGER NOT NULL AFTER id;
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-05-2007, 06:52 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Adding a new Column in middle of the Table

Hi Murali,
I am not clear for your syntax can u explain with suitable examples.

Thanks
V.Vadivelan
Buddies Infotech
Chennai
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-05-2007, 11:59 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Adding a new Column in middle of the Table

Thanks Murali now i got it
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding comment box to my website charcola PHP Programming 9 12-10-2007 11:35 AM
What is the difference between DELETE TABLE and TRUNCATE TABLE commands in SQL Server oxygen Database Support 6 11-23-2007 06:17 AM
C is a structural or highlevel or middle level language which one is correct answer vigneshgets C and C++ Programming 3 08-25-2007 01:55 PM
Problem in align a text to middle of the screen in Console Application? kingmaker C# Programming 0 07-21-2007 12:40 AM
When designing a database table, how do you avoid missing column values for non-prima Arun Database Support 2 07-18-2007 10:43 PM


All times are GMT -7. The time now is 05:26 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0