Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. an intersting sql problem

an intersting sql problem

Scheduled Pinned Locked Moved Database
databaseperformancehelptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    richardye
    wrote on last edited by
    #1

    You hava a table containing about 1000000 records.Now you want to delete 950000 records and only left 50000 records in the table. As there isn't much memory can be used, how to deal with it perfectly (both in time and in space)? many thanks

    G 2 Replies Last reply
    0
    • R richardye

      You hava a table containing about 1000000 records.Now you want to delete 950000 records and only left 50000 records in the table. As there isn't much memory can be used, how to deal with it perfectly (both in time and in space)? many thanks

      G Offline
      G Offline
      GuyThiebaut
      wrote on last edited by
      #2

      richardye wrote:

      As there isn't much memory can be used, how to deal with it perfectly (both in time and in space)?

      What is going to happen when you delete all of those records is that the transaction log is going to grow. Regarding disk space(I take it you mean disk space rather than memory?): Backup the transaction log to clear it out of pending transactions first. You will then need to shrink the transaction log. Run your script to delete the records. Then straightaway backup the transaction log and shrink it again. This is the only way I can think of to keep disk space usage at a minimum. Regarding speed: All I can suggest is that you do all of this out of hours when nobody else is using the database. If anybody else is accessing the table you are deleting from there is always the chance that you could get a lock, for a period of time, or even a deadlock.

      You always pass failure on the way to success.
      1 Reply Last reply
      0
      • R richardye

        You hava a table containing about 1000000 records.Now you want to delete 950000 records and only left 50000 records in the table. As there isn't much memory can be used, how to deal with it perfectly (both in time and in space)? many thanks

        G Offline
        G Offline
        GuyThiebaut
        wrote on last edited by
        #3

        Shrinking a transaction log is a science in itself, so here is a very useful script that I use(you may have to run the script more than once on the same transaction log for it to recover all the free space). Click here for the google document.

        You always pass failure on the way to success.
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups