delete top ( 100000 ) from myTablewhile @@rowcount > 0begindelete top ( 100000 ) from myTableend
declare @rowcount bigint = 1;declare @MaxId bigint;select @MaxId = max(x.id) from ( select top 1000 Id from myTable ) as xwhile @rowcount > 0begindelete top ( 100000 ) from myTable where Id > @MaxIdset @rowcount = @@rowcount;end
;with MyData as(select ROW_NUMBER() over(order by SomeField) as RowNum, * from YourTable)delete MyData where RowNum > 1000
CREATE TABLE Unk(Col1 INT,Col2 VARCHAR(3)) DECLARE @C INT DECLARE @B INT SET @C = 1 SET @B = 1 WHILE @C < 101 BEGIN INSERT INTO Unk SELECT @B,'abc' SET @B = @B + 1 SET @C = @C + 1 END
-- Select from table whose structure is NOT known -- Into a new table Note the first select statement -- creates a new table which I named Kn SELECT TOP(10)* INTO Kn FROM Unk ORDER BY Col1 ASC --Check that the NEW table exists and contains the required number of rows -- which in this example should be 10 SELECT COUNT(*) FROM Kn-- now rename the old and "new" tables sp_RENAME 'Unk','Junk' sp_RENAME 'Kn', 'Unk'-- now check again SELECT COUNT(*) FROM Unk