SA Developer .NET

Welcome to SA Developer .NET Sign in | Join | Help
in Search

DELETE TOP

Last post 08-12-2008, 23:36 by NeverDie. 4 replies.
Sort Posts: Previous Next
  •  08-12-2008, 22:49 13981

    DELETE TOP

    Is it possible to DELETE a TOP specified number of records from a table?

    eg. DELETE TOP 100 * FROM tb_MyTable

    The Objective is to generically batch DELETE's so that it is not dependant on a WHERE clause.

     


    A Program is only Complete when the Programmer Dies
  •  08-12-2008, 23:00 13982 in reply to 13981

    Re: DELETE TOP

    Yes, in SQL 2005 and above. You're missing brackets though

    DELETE TOP (100) FROM MyTable 


    Gail Shaw - SQL In the Wild
    SQL Server MVP
    --
    Chaos, panic and disorder. My job here is done!
  •  08-12-2008, 23:10 13983 in reply to 13982

    Re: DELETE TOP

    Wouldn't the following also work?

    SET ROWCOUNT 100
    DELETE FROM MyTable;

     



    Microsoft Xbox MVP | http://craign.net/
  •  08-12-2008, 23:30 13984 in reply to 13983

    Re: DELETE TOP

    It will. You may want to note though that ROWCOUNT is deprecated for use with data modification statements in SQL 2008.

    Gail Shaw - SQL In the Wild
    SQL Server MVP
    --
    Chaos, panic and disorder. My job here is done!
  •  08-12-2008, 23:36 13985 in reply to 13984

    Re: DELETE TOP

    Awesome; both works :)

    Thank You.

    I guess I can scrap this idea :)

    delete tb_BulkDelete

    join (select top 100 * from tb_BulkDelete) tbd on

    bd.BulkDeleteID = tbd.BulkDeleteID


    A Program is only Complete when the Programmer Dies
View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems