Subject Re: [firebird-support] limit rows in a table
Author Martijn Tonies
Hello Daniel,

> Could someone please suggest how I can limit the amount of rows a
> user
> can enter in a table, using a Stored Procedure or a trigger.
>
> I would like to limit the amount of rows to 1K, and all new inserts
> would be stopped/cancelled from this point on.
>
> How should I accomplish this?

CREATE EXCEPTION TOO_MANY_ROWS 'too many rows';

CREATE TRIGGER check_for_too_many_rows ON <table> BEFORE INSERT
AS
DECLARE VARIABLE cnt INTEGER;
BEGIN
select count(*) from <table> INTO :cnt;
if (cnt = 1024)
then exception TOO_MANY_ROWS;
end

With regards,

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, Oracle & MS SQL
Server
Upscene Productions
http://www.upscene.com
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com