在 SQL 中还原表行



目前,我正在SQL Server 2017中处理一些简单的表,并正在测试某些功能,例如插入/删除表行。

但是,假设我删除了表格行,我将如何恢复它?

我编造的一个例子是

create table employee_tbl
(
Emp_Id int primary key,
FirstName varchar(50),
LastName varchar(50),
Salary float,
MobileNo varchar(15)
)
insert into employee_tbl 
values (1, 'rajon', 'rondo', 50000, '76677676653')
select *
from employee_tbl
delete from employee_tbl 
where EmpId = 1

目前我了解如何插入和删除表行,但是删除表行后有没有办法恢复它?

testing certain functionalities such as inserting/deleting table rows.

我通常做的是将语句括在BEGIN TRANROLLBACK中。

例:

BEGIN TRAN
insert into employee_tbl values (1,'rajon','rondo',50000,'76677676653')
select *from employee_tbl
delete from employee_tbl where EmpId=1
select *from employee_tbl
ROLLBACK

在正常情况下不,一旦你删除了一行,它就消失了,除非你复制了该行。正如 dwir182 发布的那样,在该链接中它会告诉您删除后它会很快覆盖它。

最新更新