开发者

Put back deleted row from another db while preserving id field

开发者 https://www.devze.com 2023-01-09 13:54 出处:网络
I have SQL 2005 databases. I have deleted a row from one of them and want to get it back from another database that was a backup of the row.

I have SQL 2005 databases.

I have deleted a row from one of them and want to get it back from another database that was a backup of the row.

How do isnert it while preserving its id primary key identity field?

开发者_运维百科Can you give TSQL to do this assume databases are called "tbrPdata" and "tbr0910" which is the backup?

Malcolm


Use SET IDENTITY_INSERT:

SET IDENTITY_INSERT tbrPdata.dbo.TABLE ON
GO

 INSERT INTO tbrPdata.dbo.TABLE
   (col1, col2, col3,...)
 SELECT t.col1, t.col2, t.col3,...
   FROM tbr0910.dbo.TABLE t
  WHERE t.id = ?

SET IDENTITY_INSERT tbrPdata.dbo.TABLE OFF
GO
0

精彩评论

暂无评论...
验证码 换一张
取 消