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. How to Rollover a Table

How to Rollover a Table

Scheduled Pinned Locked Moved Database
databasesql-serversysadminbusinesstutorial
8 Posts 4 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
    Robert M Greene
    wrote on last edited by
    #1

    I am looking for some direction about how to keep a table in a SQL server db (2000 or above) of fixed size. Requirements: Keep n records, Keep t date/time range of records, keep priority records etc... a) Should I delete old records on insert, ie. stored proc? b) Should I delete old records with a Job/External process? c) Should I just use the the old "DELETE FROM tablename" command? Since I will be filling the table to it's limit often, and deleting the old contents should I clean up the transaction logs as well? When? How? I am just looking for some general direction. ............................. There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life. Fiat justitia, et ruat cælum

    E 1 Reply Last reply
    0
    • R Robert M Greene

      I am looking for some direction about how to keep a table in a SQL server db (2000 or above) of fixed size. Requirements: Keep n records, Keep t date/time range of records, keep priority records etc... a) Should I delete old records on insert, ie. stored proc? b) Should I delete old records with a Job/External process? c) Should I just use the the old "DELETE FROM tablename" command? Since I will be filling the table to it's limit often, and deleting the old contents should I clean up the transaction logs as well? When? How? I am just looking for some general direction. ............................. There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life. Fiat justitia, et ruat cælum

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      Use stored procedures to only return the set size. Depending on tps requirements you can then write a trigger or a job to run and clear the table removing old elements. I would use the job if you can get a way with it. The trigger, however, will always keep the table the right size. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

      F 1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        Use stored procedures to only return the set size. Depending on tps requirements you can then write a trigger or a job to run and clear the table removing old elements. I would use the job if you can get a way with it. The trigger, however, will always keep the table the right size. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

        F Offline
        F Offline
        Frank Kerrigan
        wrote on last edited by
        #3

        You can use the following script to keep the table 10000 rows. using Indentity DELETE from BigTable Where ID NOT in ( SELECT Top(10000) from BigTable ORDER BY ID DESC ) Please test first with a test table.


        Look where you want to go not where you don't want to crash. Bikers Bible

        E S 2 Replies Last reply
        0
        • F Frank Kerrigan

          You can use the following script to keep the table 10000 rows. using Indentity DELETE from BigTable Where ID NOT in ( SELECT Top(10000) from BigTable ORDER BY ID DESC ) Please test first with a test table.


          Look where you want to go not where you don't want to crash. Bikers Bible

          E Offline
          E Offline
          Ennis Ray Lynch Jr
          wrote on last edited by
          #4

          Are you sure he should first test on a test test table before testing on a test table. One can never be to careful :) A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

          R F 3 Replies Last reply
          0
          • E Ennis Ray Lynch Jr

            Are you sure he should first test on a test test table before testing on a test table. One can never be to careful :) A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

            R Offline
            R Offline
            Robert M Greene
            wrote on last edited by
            #5

            Thanks all I will give the suggestions a try. ............................. There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life. Fiat justitia, et ruat cælum

            1 Reply Last reply
            0
            • E Ennis Ray Lynch Jr

              Are you sure he should first test on a test test table before testing on a test table. One can never be to careful :) A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

              F Offline
              F Offline
              Frank Kerrigan
              wrote on last edited by
              #6

              Quite Quite Sure !


              Look where you want to go not where you don't want to crash. Bikers Bible -- modified at 9:54 Tuesday 18th July, 2006

              1 Reply Last reply
              0
              • E Ennis Ray Lynch Jr

                Are you sure he should first test on a test test table before testing on a test table. One can never be to careful :) A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

                F Offline
                F Offline
                Frank Kerrigan
                wrote on last edited by
                #7

                Please call me skippy


                Look where you want to go not where you don't want to crash. Bikers Bible

                1 Reply Last reply
                0
                • F Frank Kerrigan

                  You can use the following script to keep the table 10000 rows. using Indentity DELETE from BigTable Where ID NOT in ( SELECT Top(10000) from BigTable ORDER BY ID DESC ) Please test first with a test table.


                  Look where you want to go not where you don't want to crash. Bikers Bible

                  S Offline
                  S Offline
                  S Douglas
                  wrote on last edited by
                  #8

                  Frank Kerrigan wrote:

                  Please test first with a test table.

                  Test? I think you mean test in Production! (is it Friday yet?) :)


                  I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

                  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