delimiting table size

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default delimiting table size

    I would like to delimit a table to the newest 2000 entries
    [for site hit logging]

    I use ADODB and Microsoft.Jet.OLEDB.4.0

    ==========

    Any sense in this PSEUDO! sql code [ID is autoincrement]:

    Insert into table1 (field1,field2) values (1,2)
    .... execute
    Delete first(ID) from table1 order by ID where count(ID)>2000
    .... execute

    ===========

    Can I reduce a much longer table to the latest 2000 entries?

    Repeat Delete first(ID) from table1 order by ID WHILE count(ID)>2000

    [Yes I know repeat..while is not sql]

    ===========

    Please hint me in the right direction.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

  2. Similar Questions and Discussions

    1. Myisam Table size
      Hi all, table size on mysql ( win XP ), is known as being at least 2 GO. but what i see in structure field of phpmyadmin is Type Espace...
    2. Perfect table size
      Why the tables sometimes expanding & exceeding the exact size when i do preview on IE, for example if the table is 250pixels in DW and when u...
    3. DB and table size
      I want create a php, to make a report, to know which DB's and that DB's tables' size. I had consulted phpmyadmin, but it is too complicated, I...
    4. db2 table size.
      Hi all Without getting too technical is he following deduction correct Table size = (Number of rows X lenght of a record)/1024 if not how...
    5. Table Size
      http://www.aspfaq.com/2428 -- Aaron Bertrand, SQL Server MVP http://www.aspfaq.com/ Please reply in the newsgroups, but if you absolutely...
  3. #2

    Default Re: delimiting table size

    Evertjan. wrote:
    > I would like to delimit a table to the newest 2000 entries
    > [for site hit logging]
    >
    > I use ADODB and Microsoft.Jet.OLEDB.4.0
    >
    > ==========
    >
    > Any sense in this PSEUDO! sql code [ID is autoincrement]:
    >
    > Insert into table1 (field1,field2) values (1,2)
    > ... execute
    > Delete first(ID) from table1 order by ID where count(ID)>2000
    > ... execute
    >
    No
    > ===========
    >
    > Can I reduce a much longer table to the latest 2000 entries?
    >
    > Repeat Delete first(ID) from table1 order by ID WHILE count(ID)>2000
    >
    > [Yes I know repeat..while is not sql]
    >
    > ===========
    >
    > Please hint me in the right direction.
    Create a new table with the same structure. Then,

    INSERT into newtable
    SELECT TOP 2000 ... from table1 ORDER BY ...

    DELETE * FROM table1
    INSERT into table1
    SELECT ... from newtable
    DELETE * FROM newtable

    HTH,
    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows [MVP] Guest

  4. #3

    Default Re: delimiting table size

    Bob Barrows [MVP] wrote on 06 mei 2004 in
    microsoft.public.inetserver.asp.db:
    > Evertjan. wrote:
    >> Please hint me in the right direction.
    >
    > Create a new table with the same structure. Then,
    >
    > INSERT into newtable
    > SELECT TOP 2000 ... from table1 ORDER BY ...
    >
    > DELETE * FROM table1
    > INSERT into table1
    > SELECT ... from newtable
    > DELETE * FROM newtable
    Tnx, Bob,

    Won't the last solution have the [theoretical?] possibility of deleting
    a fresh simultaneous insert from another session ???

    I will experiment with your solution.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

  5. #4

    Default Re: delimiting table size

    Evertjan. wrote:
    > Bob Barrows [MVP] wrote on 06 mei 2004 in
    > microsoft.public.inetserver.asp.db:
    >> Evertjan. wrote:
    >>> Please hint me in the right direction.
    >>
    >> Create a new table with the same structure. Then,
    >>
    >> INSERT into newtable
    >> SELECT TOP 2000 ... from table1 ORDER BY ...
    >>
    >> DELETE * FROM table1
    >
    >> INSERT into table1
    >> SELECT ... from newtable
    >> DELETE * FROM newtable
    >
    > Tnx, Bob,
    >
    > Won't the last solution have the [theoretical?] possibility of
    "last solution"? There's a single solution here consisting of 4 steps:

    1. insert the top 2000 records into the newtable
    2. delete all records from table1
    3. insert the 2000 records from newtable into tsble1
    4. delecte all the records from newtable


    Or did you mean "step" when you said "solution"?
    > deleting a fresh simultaneous insert from another session ???

    Wrapping these steps in a transaction will prevent this type of problem. You
    should use a transaction anyways so that it can be rolled back if any of the
    steps fails.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

  6. #5

    Default Re: delimiting table size

    Bob Barrows [MVP] wrote on 06 mei 2004 in
    microsoft.public.inetserver.asp.db:
    > Evertjan. wrote:
    >> I would like to delimit a table to the newest 2000 entries
    >> [for site hit logging]
    >>
    >> I use ADODB and Microsoft.Jet.OLEDB.4.0
    >>
    >> ==========
    >>
    >> Any sense in this PSEUDO! sql code [ID is autoincrement]:
    >>
    >> Insert into table1 (field1,field2) values (1,2)
    >> ... execute
    >> Delete first(ID) from table1 order by ID where count(ID)>2000
    >> ... execute
    >>
    >
    > No
    >
    I made this as a [working!] solution:

    randomize()
    inserts(int(rnd()*33)) ' inserts random integer 0...32
    maximizes(9) ' deleting the oldest records maximizes to 9
    writes()

    function inserts(x) ' inserts x value in new record
    SQL = "Insert into Tabel1 (naam) VALUES ("&x&")"
    'response.write "<hr>" & SQL & "<hr>"
    set mDATA=CONNECT.Execute(SQL)
    end function

    function maximizes(x) ' deletse oldest records till x are left
    SQL = "SELECT count(*) as counting FROM Tabel1"
    'response.write "<hr>" & SQL & "<hr>"
    set mDATA=CONNECT.Execute(SQL)
    counting = mDATA("counting")

    while counting>x
    SQL = "SELECT min(ID) as minid FROM Tabel1"
    'response.write "<hr>" & SQL & "<hr>"
    set mDATA=CONNECT.Execute(SQL)
    minid = mDATA("minid")

    SQL = "DELETE * FROM Tabel1 WHERE ID = " & minid
    'response.write "<hr>" & SQL & "<hr>"
    set mDATA=CONNECT.Execute(SQL)

    SQL = "SELECT count(*) as counting FROM Tabel1"
    'response.write "<hr>" & SQL & "<hr>"
    set mDATA=CONNECT.Execute(SQL)
    counting = mDATA("counting")
    wend
    end function

    function writes() ' writes the table contents
    SQL = "Select ID,naam from Tabel1"
    'response.write "<hr>" & SQL & "<hr>"
    set mDATA=CONNECT.Execute(SQL)
    n = 1
    Do Until mData.Eof
    Response.Write n & ": "
    Response.Write mData("ID") & " - "
    Response.Write mData("naam") & "<br>"
    n = n + 1
    mData.MoveNext
    Loop
    end function

    Can this be done simpler ?


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

  7. #6

    Default Re: delimiting table size

    Evertjan. wrote:
    > I made this as a [working!] solution:
    >
    > randomize()
    > inserts(int(rnd()*33)) ' inserts random integer 0...32
    > maximizes(9) ' deleting the oldest records maximizes to 9
    > writes()
    >
    > function inserts(x) ' inserts x value in new record
    > SQL = "Insert into Tabel1 (naam) VALUES ("&x&")"
    > 'response.write "<hr>" & SQL & "<hr>"
    > set mDATA=CONNECT.Execute(SQL)
    > end function
    >
    > function maximizes(x) ' deletse oldest records till x are left
    > SQL = "SELECT count(*) as counting FROM Tabel1"
    > 'response.write "<hr>" & SQL & "<hr>"
    > set mDATA=CONNECT.Execute(SQL)
    > counting = mDATA("counting")
    >
    Maybe something like this:
    if x < counting then
    SQL = "DELETE * FROM Tabel1 WHERE ID IN " & _
    "(SELECT TOP " & counting - x & " ID FROM " & _
    "table1 ORDER BY ID asc)"
    end if

    At least that would get rid of the loop.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

  8. #7

    Default Re: delimiting table size

    Bob Barrows [MVP] wrote on 06 mei 2004 in
    microsoft.public.inetserver.asp.db:
    > Maybe something like this:
    > if x < counting then
    > SQL = "DELETE * FROM Tabel1 WHERE ID IN " & _
    > "(SELECT TOP " & counting - x & " ID FROM " & _
    > "table1 ORDER BY ID asc)"
    > end if
    >
    > At least that would get rid of the loop.
    This works very nice.
    [took me half an hour to see
    the difference beween tabel1 and table1 ;-)]

    I will start to overhaul the logging in textfiles from 3 years ago.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139