Move SQL data from one table to another

后端 未结 13 2898
梦如初夏
梦如初夏 2020-11-29 20:34

I was wondering if it is possible to move all rows of data from one table to another, that match a certain query?

For example, I need to move all table rows from Tab

13条回答
  •  误落风尘
    2020-11-29 21:20

    This is an ancient post, sorry, but I only came across it now and I wanted to give my solution to whoever might stumble upon this one day.

    As some have mentioned, performing an INSERT and then a DELETE might lead to integrity issues, so perhaps a way to get around it, and to perform everything neatly in a single statement, is to take advantage of the [deleted] temporary table.

    DELETE FROM [source]
    OUTPUT [deleted].
    INTO [destination] ()
    

提交回复
热议问题