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
 SQL Server Development (2000)
 SQL Sscript

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-22 : 09:09:47
Prajakta writes "I want to create a new empty table with same structure as another table. Thne i would like to change the datatype of one fiels in this new table. After this finally transfer the data from first table into new table."

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-04-22 : 09:16:59
OK

Just do it

Firstly, why not just manually create a table ?

But I know you are going to find some reason why you can't do it. So....

Create the blank table by using a Select Into


Select *
Into MyNewTable
From MyOldTable
WHERE 1=0 --this will return 0 rows


Then alter the table and column


Alter Table MyNewTable
Alter Column MyColumn varchar(30) --or whatever your new datatype is


then copy the data


Insert Into MyNewTable
Select * From MyOldTable


That should do it

Damian
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2002-04-23 : 20:19:22
And don't forget you could also just do

select column1, column2, CAST(column3 as NewType)
into MyNewTable
from MyOldTable[/b]



--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -