Not in
SET STATISTICS time on
Go
--Backup data
Insert into Bakinfo (id,pname,remark,impdate,ups tutorial Tate)
Select Id,pname,remark,impdate,upstate from dbo. Info
where ID not in (SELECT ID from Dbo.bakinfo)
Go
SET STATISTICS Time off
SQL Server profiling and compilation time:
CPU time = 0 milliseconds, elapsed time = 3 milliseconds.
SQL Server Execution Time:
CPU time = 453 milliseconds, elapsed time = 43045 milliseconds.
(100000 rows affected)
SQL Server profiling and compilation time:
CPU time = 0 milliseconds, elapsed time = 1 milliseconds.
--Change the current table state
Update Info set upstate=1 where ID in (select ID from Dbo.bakinfo)
CREATE PROCEDURE AddData
As
DECLARE @id int
Set @id =0
while (@id <100000)
Begin
INSERT INTO dbo. Info (Id,pname,remark,impdate,upstate)
VALUES (@id, convert (varchar, @id) + ' 0 ', ' abc ', GETDATE (), 0)
Set @id = @id +1
End
EXEC AddData
SQL Server profiling and compilation time:
CPU time = 62 milliseconds, elapsed time = 79 milliseconds.
SQL Server Execution Time:
CPU time = 188 milliseconds, elapsed time = 318 milliseconds.
(100000 rows affected)
SQL Server profiling and compilation time:
CPU time = 0 milliseconds, elapsed time = 1 milliseconds.
--Delete Current table data
Delete from Info where upstate=1 and IDs in (select IDs from Dbo.bakinfo)
SET STATISTICS time on
Go
--Backup data
Insert into Bakinfo (id,pname,remark,impdate,upstate)
Select Id,pname,remark,impdate,upstate from
(SELECT info.id,info.pname, Info.remark, Info.impdate,info.upstate, bakinfo.id as Bakid
From Info left JOIN
Bakinfo on info.id = bakinfo.id) as T
Where T.bakid is null and t.upstate=0
Go
SET STATISTICS time off;
SQL Server parse and compile time:
CPU time = 247 milliseconds, elapsed time = 247 milliseconds.
SQL Server Execution time:
CPU time = 406 milliseconds, elapsed time = 475 milliseconds.
(100000 rows affected)
SQL Server parse and compile time:
CPU time = 0 milliseconds, elapsed time = 1 milliseconds.
--Change the current table state
Update Info set upstate=1
from Info INNER JOIN
bakinfo on info.id = bakinfo.id