Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

simple ALTER Table query question...SQL 2000.

 
   Database Forums (Home) -> General Discussions RSS
Next:  Update Query Runs Forever  
Author Message
quincy451

External


Since: Jun 03, 2008
Posts: 3



(Msg. 1) Posted: Tue Jun 03, 2008 8:37 am
Post subject: simple ALTER Table query question...SQL 2000.
Archived from groups: comp>databases>ms-sqlserver (more info?)

Ok I have a table with fields as follows:
field1
varchar(10)

field2
varchar(10)

field3
varchar(10)

Identity
int
Indenity field

I want to create a ALTER table to add fields field2a and field2b right
after field2 and not at the end of the table. Any way to do this?

Thanks,
David

 >> Stay informed about: simple ALTER Table query question...SQL 2000. 
Back to top
Login to vote
Plamen Ratchev

External


Since: Nov 06, 2007
Posts: 352



(Msg. 2) Posted: Tue Jun 03, 2008 12:15 pm
Post subject: Re: simple ALTER Table query question...SQL 2000. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

The order of the columns does not matter as you define the column order when
writing queries in your SELECT statement.

If you really want to accomplish this, you can create table with temporary
name with the desired column sequence, then insert the data from the
original table into the new table, drop the old table, and rename the new
table to the original table name (using sp_rename). Since you have IDENTITY
column you may have to use SET IDENTITY_INSERT to ON to preserve the column
values.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

 >> Stay informed about: simple ALTER Table query question...SQL 2000. 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 1649



(Msg. 3) Posted: Tue Jun 03, 2008 9:41 pm
Post subject: Re: simple ALTER Table query question...SQL 2000. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

( ) writes:
> Ok I have a table with fields as follows:
> field1
> varchar(10)
>
> field2
> varchar(10)
>
> field3
> varchar(10)
>
> Identity
> int
> Indenity field
>
> I want to create a ALTER table to add fields field2a and field2b right
> after field2 and not at the end of the table. Any way to do this?

No, ALTER TABLE is very limited and only permits you to add columns
as the last column in the table. No wonder that I hardly ever use it.
You would need to create new table and copy data over, a certainly more
complicated process.

There is an old request to change ALTER TABLE to permit this that you mayu
want to vote on:
https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?Fee...ckID=12


--
Erland Sommarskog, SQL Server MVP, esquel RemoveThis @sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
 >> Stay informed about: simple ALTER Table query question...SQL 2000. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
simple SQL question to insert records in an existing table.. - Hi, I would like to know how to modify the following selects so that - assuming that NewTable already exists - the result of the SELECT is appended to the existing table. If possible I need the appropriate changes for both the 2 syntax below. -1- SELEC...

trigger simple question - I am looking at a table in Microsoft SQL Server. I went to the dependencies of this table and it says TRIG_customer. so i am thinking there is a trigger that affects the table but how do i see what is the code that resides within this trigger. I looked..

Simple JOIN, INTERSECT query - Hi, We are in the process of buying a new server to run mssql. However before this as a tempory fix to using a msaccess backend i believe through odbc i need to address the following issue: SELECT ai.entry_date as CallTime, ai.agent_logi...

change structure of a simple query - Hello, I would like to do a little query in T-SQL. I have two tables: PERSON (PERSONID, PERSON) PHONE ( PHONEID, PERSONID, TYPE, PHONE) -- TYPE can be (business, fax, business 2) If I do a simple select I will get SELECT PERSONID, PESON, TYPE, PHONE...

A simple query that returns the most current address - Hi, I have an Address table which contains more than one addresses for a particular member. I want to write a query that would only display most current address. All addresses have a unique ID (addID). Example: memberID addID address1 -------- ------....
   Database Forums (Home) -> General Discussions All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]