SQL Serveri without cursors, suitable for instance instances of cyclic DML (update delete insert)
Use TEMPDBGOIF exists (SELECT * from tempdb. sysobjects where id=object_id (' tempdb. #tbl_Cursor ')) DROP TABLE #tbl_Cursorif exists (SELECT * from tempdb. sysobjects where id=object_id (' tempdb. #tbl_Value ')) DROP table #tbl_Valuegoif object_id (N ' testdata ') is not nulldrop table Testdataselect row_number () over ( ORDER by A.storeid) id,* to Testdatafrom Sys.tablesselect row_number () over (order by A.storeid) idd,* into #tbl_CursorFR OM testdata where Id%3=0set @[email protected] @rowcountCREATE CLUSTERED INDEX cix_tbl_tmp on #tbl_Cursor (ID) SELECT * into #tbl_Value from #tbl_Cursor WHERE 1=2while @tbl_rows >0begintruncate TABLE #tbl_ValueDELETE from #tbl_Cursor OUTP UT deleted.* into #tbl_Value WHERE [Email protected]_rows--select * from Testdataupdate top T1 set id=id+10000 from testdata T1 INNER join #tbl_Value on #tbl_Value. Id=t1.idselect * from testdata deleted top T1 from testdata t1 inner Joi n #tbl_Value on #tbl_Value. Id=t1.idselect * from testdata insert to TestData SelecT *,........ from #tbl_Valueselect * from Testdataset @[email protected]_rows-1end
SQL Serveri without cursors, suitable for instance instances of cyclic DML (update delete insert)