April 14, 2008 at 5:08 am
Hi,
I have a select statement for moving data to another server not linked.The problem is that the destination table does not exist and must be created.How do i obtain the structure of the table resulted from the select without creating the table temporary in the source database, so i can create it on the other server using C#?
Thank you
April 14, 2008 at 6:21 am
[font="Verdana"]
try this ...
Select * Into {New Table Name} From {Old Table Name}
This will create new table with the data and structure of old table. And if you want only structure then...
Select * Into {New Table Name} From {Old Table Name} Where {1 = 2}
confirm on this.
Mahesh
[/font]
MH-09-AM-8694
April 14, 2008 at 6:24 am
You could use replication for this but I suspect you're trying to build a "Gold Set" or something similar one table at a time. You could use SELET/INTO which will build the column schema and copy the data, but across Linked Servers, you'll loose all other column attributes such as IDENTITY, etc and, of course, it won't copy any keys or indexes.
If you want to maintain all of that in the copy, you'll need to build a script that will build the CREATE statement for all of that... not something that most folks would be willing to do for free on a forum....
HOWEVER... DTS or SSIS will do it for you...
--Jeff Moden
Change is inevitable... Change for the better is not.
April 14, 2008 at 6:31 am
Mahesh Bote (4/14/2008)
[font="Verdana"]try this ...
Select * Into {New Table Name} From {Old Table Name}
This will create new table with the data and structure of old table. And if you want only structure then...
Select * Into {New Table Name} From {Old Table Name} Where {1 = 2}
confirm on this.
Mahesh
[/font]
I knew about this solution, but I was asking for one that doesn't modify the database.
Jeff Moden (4/14/2008)
You could use replication for this but I suspect you're trying to build a "Gold Set" or something similar one table at a time. You could use SELET/INTO which will build the column schema and copy the data, but across Linked Servers, you'll loose all other column attributes such as IDENTITY, etc and, of course, it won't copy any keys or indexes.If you want to maintain all of that in the copy, you'll need to build a script that will build the CREATE statement for all of that... not something that most folks would be willing to do for free on a forum....
HOWEVER... DTS or SSIS will do it for you...
Thanks, I'll look into it.My temporary solution is to create the schema on source server(not linked servers), get the create script and delete the temp table, not sure if there are any issues i should be concerned, perhaps you could tell me.
Thank you
Edit: One issue I found was scripting Identity, which i had to remove
April 14, 2008 at 10:35 am
Temp table???? What temp table????
--Jeff Moden
Change is inevitable... Change for the better is not.
April 15, 2008 at 12:37 am
Jeff Moden (4/14/2008)
Temp table???? What temp table????
By temp table i meant the one created by select..into..where 1=0 statement ran on source server, which has the only use for me to get the schema.Sorry i said temp table, i know it got you confusded 🙂
April 15, 2008 at 6:03 am
Heh... ok... thanks for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply