473,699 Members | 2,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

restricting table size

Say I want to make sure that a table can not have more than 100 records
- how could I do this from MYSQl or PHP.

Thanks
Jul 23 '05 #1
4 1246
Hal Halloway wrote:
Say I want to make sure that a table can not have more than 100 records
- how could I do this from MYSQl or PHP.


Have you looked at the MAX_ROWS table option?

e.g.,

CREATE TABLE (
...column definitions...
) MAX_ROWS = 100;

See http://dev.mysql.com/doc/mysql/en/create-table.html

Regards,
Bill K.
Jul 23 '05 #2

"Bill Karwin" <bi**@karwin.co m> skrev i en meddelelse
news:ct******** @enews2.newsguy .com...
Hal Halloway wrote:
Say I want to make sure that a table can not have more than 100 records -
how could I do this from MYSQl or PHP.


Have you looked at the MAX_ROWS table option?

e.g.,

CREATE TABLE (
...column definitions...
) MAX_ROWS = 100;

See http://dev.mysql.com/doc/mysql/en/create-table.html

It appears from the docs that MAX_ROWS is only used when creating the table
to hint for the database engine the most efficient way to store the data.

It doesn't look like it is being enforced when inserting rows.

But try, and report back.

Leif
Jul 23 '05 #3
"Leif Neland" <le***@neland.d k> wrote in
news:yp******** *******@news.ge t2net.dk:
It appears from the docs that MAX_ROWS is only used when creating the
table to hint for the database engine the most efficient way to store
the data.

It doesn't look like it is being enforced when inserting rows.

But try, and report back.


if that's the case, you can just do a COUNT(*) before inserting into your
table... ie: don't allow inserts when the Count >= 100

Jul 23 '05 #4

"Hal Halloway" <Ha******@nospa m.net> wrote in message
news:rRXKd.2043 $qP.161@trnddc0 4...
Say I want to make sure that a table can not have more than 100 records
- how could I do this from MYSQl or PHP.


You haven't mentioned what rule you want to apply that decides which records
you want to delete when the table grows beyond 100 records. And I haven't
tried MAX_ROWS myself and I am not clear how that works. If it serves, that
might be best. Otherwise, here is what I would do.

I'm going to assume you want to toss the oldest records and you have an
autonumbered key field. In this case, you will want to toss the records with
the smallestKeyId values to cut back down to 100 records.

# Skip past the most recent 100 records and fetch the next
# highest key value.
SELECT {AutoNumbered_K eyID} As HighestKeyToKil l
FROM {SomeTable}
ORDER BY {AutoNumbered_K eyID}DESC # biggest (newest) keys to the top!
LIMIT 1, 101 # 101 will be
the first record to delete!

# Now delete all records that are at or smaller than your HighestKeyToKil l
value
DELETE FROM SomeTable
WHERE KeyID<=$Highest KeyToKill

If you are MySQL version 4.1 or higher you can do that in one query with the
SELECT in a subquery.

Everytime you do this, your table gets trimmed back down to 100 records by
tossing out older records. You can hang it on a cron to do it every once in
a while. Commonly, I do something similar when I need to toss records that
are older than 90 (or whatever!) days and I have a datetime field to work
with. I'm sure you can see how to adapt.

If there is something critical about never exceeding 100 records, you will
have to do your trim immediately before adding records. I.E before you add 5
recs, you will need to delete 5 first.

Thomas Bartkus

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1807
by: Finalstryke | last post by:
Hi, I run a hobby-based hall of fame. At the moment people send their stats to me and I manually update the database, run the queries, and convert the results to .pdf which is then put online. I'm in the process of automating the procedure by changing to a .php website with the Hall of Fame powered by a mysql database, but what I'm trying to figure out is if each user has a unique username and password, is it possible for the database...
3
2150
by: Harry_Crow | last post by:
I want to restrict the minimum size of the form. I find that there are properties MaximumSize and MinimumSize. This will help you control the maximum and minimum size the form, when the form is resized. but I find using this will make the controls on the form to flicker more. one can even restrict using WM_SIZING message but the position of the window is changing slowly while doing so. does anyone know the logic how the window minimum size...
4
16662
by: no-spam | last post by:
Hello, I have an HTML question that I'm not sure can be solved. I want to restrict the maximum size of an inline image. For example, I can force the image to be 200x200 if I do this: <img src=blah.gif width=200 height=200> But, that messes up the aspect ratio, and could size the image larger than it's original size.
2
1599
by: hoenes1 | last post by:
Hi all, I have an asp.net application from which registered users can download files. What I want to implement is a bandwidth restriction for certain users. What I DON'T want to do is restrict the bandwidth on the IIS side. It really should be handled in the code. Here is a code snippet showing how downloads are currently handled (standard implementation I guess): // fs: FileStream
2
2087
by: Pekka Henttonen | last post by:
Is there a way to limit the size of a database backup file (instead of one huge file to have several smaller ones)? The command does not seem to have any suitable options, as far as I can see.
2
6878
by: G | last post by:
I would like to restrict the number of digits in a number field in the design of a table. eg. 16 digits maximum in a certain number field of a table. thanks.
5
1351
by: ronchito | last post by:
Hi, I have a database that contains only one table. This table contains highly confidential/unique information that, if viewed or copied as a whole, would give away much of my company's intellectual property. So, obviously we don't want users to have direct access to view, modify, etc. this table. However, there is a form in this database that uses data from that table to calculate averages, etc. I'd like the form to have access to the...
5
1648
by: MLH | last post by:
I have a form based on a table that is opened this way... DoCmd.OpenForm "frmAdminSetupInfo", , , , A_EDIT It was my intention that the form allow the user to edit table data - not add records. The table contains a single record only. I don't want more records be added to the table. When frmAdminSetupInfo opens, all one has to do to go to a newrec (empty new record) is press PGDN or hold down
4
1791
by: Jacob.Bruxer | last post by:
I've been unable to find a simple answer to what I initially thought was going to be a simple question. I want to be able to restrict the size of my forms in a VB.net project. I don't want users to be able to make the forms either smaller or bigger than the size I've set them at. How is this done? Thanks.
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8613
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.