I am trying to write a query that deletes records from one table and outputs the deleted records into another similar (but not identical) table.
This code is what I am trying to do:
delete from MyServer.dbo.t1
output deleted.colA into MyServer.dbo.t2.colA
It raises the error, could not find server ‘MyServer’ in sys.servers.
However, I am able to run this (basically no-op) code (using a valid server name):
delete from MyServer.dbo.t1
output deleted.* into MyServer.dbo.t1
So basically t-sql’s error message does not seem to make sense–so I am not sure what to do.
-
why is t-sql throwing this weird error? why can it “see” MyServer in sys.servers sometimes but not other time?
-
what is the correct syntax for outputting deleted values for particular columns into new tables
When you use 3
.in your syntax, you are specifyingserver.database.schema.table. You are trying to add column on the end which does not work. Get rid of the.colA.