Domnic
Domnic

Reputation: 5297

Copy table from one server to another using select statement

I need to copy a table from one server to another.for that I have did the below code,

select * into tbls from SNRJDI-32962\xxxmanagement.master.dbo.tbl

When I execute I got error Like,

Msg 102, Level 15, State 1, Line 2 Incorrect syntax near '-'.

but this is the actual server name(SNRJDI-32962\xxxmanagement)..Please do needful..

Thank you

Upvotes: 0

Views: 2041

Answers (2)

David Laplante
David Laplante

Reputation: 109

I would add to Andomar's answer that to have special characters in an object name, you need to surround the name in [square brackets] otherwise sql will interpret your "-" as a minus sign

Upvotes: 0

Andomar
Andomar

Reputation: 238086

You first have to add a linked server from the target server to the source server.

Then you can use a four-part name, separated by dots:

select * into [newtable] from [linked_server].[databasename].dbo.[tablename]

Upvotes: 4

Related Questions