Purge/Delete records from a table

  • hello,

    have to delete records from a table SELECT * FROM [DB_NAME].[dbo].[Table_Name].Insert_Datetime (Column)

    there are million of records, please help me what is best possible way to delete them?

  • An oldie but goodie: Deleting Large Number of Rows[/url]. Note the SQL 2005 code is compatible with all newer versions of SQL Server.

    The technique in the article will delete rows in batches as small as needed to allow other queries access to the table in between operations so you do not affect performance of the database too greatly while deleting the data.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Use Truncate table deletes all the rows in that table

    TRUNCATE TABLE LargeTable

    GO

  • LOL

  • A third option is to drop and recreate the table.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • johnwalker10 (1/13/2016)


    Use Truncate table deletes all the rows in that table

    TRUNCATE TABLE LargeTable

    GO

    True, but it will be useful if you have simple recovery model for your db.

    and put a CHECKPOINT after every delete query (which should happen in loop) to truncate the log

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply