Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 ALTER TABLE queston

Author  Topic 

MichaelP
Jedi Yak

2489 Posts

Posted - 2003-09-12 : 18:04:54
I'm trying to learn how to use QA for everything and get away from EM.

How to I do an ALTER TABLE and add a new Column exactly where I want it in the table? I know it doesn't really matter, but it would be nice if I can put it between these two other columns.


--This works, but it puts it as the last field in the table.
ALTER TABLE Account ADD BillNotes VARCHAR(255) NULL


Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-09-12 : 18:09:49
You have to create a temporary table with the columns in the right order. Move all of the data into the temporary table and putting data in the new column (NULL or default value or something like that), drop the table, then rename the temporary table to the other name. You can easily see the script for this by making the change in EM but not saving it. Click the save change script button. You'll see exactly how it should be written.

Tara
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2003-09-12 : 18:33:16
Yeah, I just saw how EM was doing it. I was hoping there was another way. I guess I'll just use EM in this case.

Thanks Princess Tara!

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page
   

- Advertisement -