The document describes using a MERGE statement in SQL to undelete records in a database table. It shows merging two tables, People1.dbo.Persons1 and People2.dbo.Persons1, and updating the IsDeleted field to 0 for any matched records that have IsDeleted = 1 in the first table. It then demonstrates matching on the FirstName field instead of the id field to update the IsDeleted field for a specific name.
The document describes using a MERGE statement in SQL to undelete records in a database table. It shows merging two tables, People1.dbo.Persons1 and People2.dbo.Persons1, and updating the IsDeleted field to 0 for any matched records that have IsDeleted = 1 in the first table. It then demonstrates matching on the FirstName field instead of the id field to update the IsDeleted field for a specific name.
The document describes using a MERGE statement in SQL to undelete records in a database table. It shows merging two tables, People1.dbo.Persons1 and People2.dbo.Persons1, and updating the IsDeleted field to 0 for any matched records that have IsDeleted = 1 in the first table. It then demonstrates matching on the FirstName field instead of the id field to update the IsDeleted field for a specific name.
MERGE People1.dbo.Persons1 p1 USING People2.dbo.Persons1 p2 ON p1.id = p2.id WHEN MATCHED AND p1.IsDeleted = 1 THEN UPDATE SET p1.IsDeleted = 0;
Match IsDeleted by FirstName
DECLARE @FirstName NVARCHAR(MAX) SET @FirstName = 'Karen' MERGE People2.dbo.Persons1 p1 USING People1.dbo.Persons1 p2 ON p1.id = p2.id WHEN MATCHED AND p1.FirstName = @FirstName THEN UPDATE SET p1.IsDeleted = p2.IsDeleted;
SELECT id, FirstName,IsDeleted FROM People1.dbo.Persons1 WHERE FirstName = 'Karen'
SELECT id, FirstName, IsDeleted FROM People2.dbo.Persons1 WHERE FirstName = 'Karen'