1

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.

  1. why is t-sql throwing this weird error? why can it "see" MyServer in sys.servers sometimes but not other time?

  2. what is the correct syntax for outputting deleted values for particular columns into new tables

1 Answer 1

1

When you use 3 . in your syntax, you are specifying server.database.schema.table. You are trying to add column on the end which does not work. Get rid of the .colA.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks! how do I specify the column name without the "three dot" syntax? When I just remove column A as you suggest, I get column name or number of supplied values does not match table definition because the source table has many more columns than the target table
Unfortunately it is a limitation of what you are trying to do, you have to insert into a table that matches the schema you are pulling out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.