Is there a way to limit the number of rows in a table? Lets say I
want to only allow 1000 records to be inserted into a table. Can I
CREATE or ALTER TABLE and set it to only allow a max 1000 record ? I
did not see the option available under either of these. 9 10925
On Sep 11, 5:09 pm, shorti <lbrya...@juno.comwrote:
Is there a way to limit the number of rows in a table? Lets say I
want to only allow 1000 records to be inserted into a table. Can I
CREATE or ALTER TABLE and set it to only allow a max 1000 record ? I
did not see the option available under either of these.
How about creating an insert trigger?
"shorti" <lb******@juno.comwrote in message
news:11**********************@e34g2000pro.googlegr oups.com...
Is there a way to limit the number of rows in a table? Lets say I
want to only allow 1000 records to be inserted into a table. Can I
CREATE or ALTER TABLE and set it to only allow a max 1000 record ? I
did not see the option available under either of these.
Something like this perhaps:
CREATE TABLE tbl
(x INT NOT NULL PRIMARY KEY, CHECK (x BETWEEN 1 AND 1000),
.... );
--
David Portas
On Sep 11, 2:54 pm, Mark A <m00...@yahoo.comwrote:
On Sep 11, 5:09 pm, shorti <lbrya...@juno.comwrote:
Is there a way to limit the number of rows in a table? Lets say I
want to only allow 1000 records to be inserted into a table. Can I
CREATE or ALTER TABLE and set it to only allow a max 1000 record ? I
did not see the option available under either of these.
How about creating an insert trigger?
ok..thanks Mark I will do that. I was just hoping I was missing
something that allowed you to set up the table that way.
On Sep 11, 4:09 pm, shorti <lbrya...@juno.comwrote:
Is there a way to limit the number of rows in a table? Lets say I
want to only allow 1000 records to be inserted into a table. Can I
CREATE or ALTER TABLE and set it to only allow a max 1000 record ? I
did not see the option available under either of these.
CREATE TABLE Foobar
(size_control INTEGER NOT NULL
CHECK (size_control BETWEEN 1 AND 1000) UNIQUE,
etc.);
Shorti,
You could just use a before trigger with:
CREATE TRIGGER trg1 BEFORE INSERT ON T
REFERENCING NEW_TABLE AS NEWTAB
FRO EACH STATEMENT
WHEN ((SELECT COUNT(*) FROM T) + (SELECT COUNT(*) FROM NEWTAB) 1000)
SIGNAL SQLSTATE '78000' SET MESSAGE_TEXT = 'Table too big'
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Another idea.
CREATE TABLE LimitRows
(PK INTEGER NOT NULL
,Data1 VARCHAR(5) NOT NULL
)
ORGANIZE BY KEY SEQUENCE (PK STARTING 1 ENDING 10)
DISALLOW OVERFLOW
;
INSERT INTO LimitRows
SELECT PK, 'AAA'
FROM (VALUES 2,3,5,8,9) S(PK)
;
Insert one row.
INSERT INTO LimitRows
SELECT COALESCE(MIN(COALESCE(A.PK, N.PK)), 10) + 1, 'BBB'
FROM LimitRows A
FULL OUTER JOIN
(SELECT NULLIF(COUNT(*),1)
FROM LimitRows
WHERE PK = 1
) N (PK)
ON N.PK = A.PK
WHERE NOT EXISTS
(SELECT *
FROM LimitRows B
WHERE B.PK = A.PK + 1
)
AND COALESCE(A.PK, N.PK) < 10
;
Repeat 4 times by changing Data1 to 'CCC','DDD','EEE','FFF'.
(Filled all 10 rows)
Next Insert gets error message:
SQL1870N A row could not be inserted into a range-clustered table
because a key sequence column is out of range.
Final result is....
----------------------- Commands Entered -----------------------
SELECT * FROM LimitRows;
----------------------------------------------------------------
PK DATA1
----------- -----
1 BBB
2 AAA
3 AAA
4 CCC
5 AAA
6 DDD
7 EEE
8 AAA
9 AAA
10 FFF
10 record(s) selected.
On Sep 13, 5:35 am, Serge Rielau <srie...@ca.ibm.comwrote:
Shorti,
You could just use a before trigger with:
CREATE TRIGGER trg1 BEFORE INSERT ON T
REFERENCING NEW_TABLE AS NEWTAB
FRO EACH STATEMENT
WHEN ((SELECT COUNT(*) FROM T) + (SELECT COUNT(*) FROM NEWTAB) 1000)
SIGNAL SQLSTATE '78000' SET MESSAGE_TEXT = 'Table too big'
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Yes...that is almost the exact trigger I created for this. Thanks.
>Now I would have to parse [table scan?] the table to find the UNIQUE size_control values to find the available ones. <<
SELECT MIN(size_control +1)
FROM Foobar
WHERE size_control +1
NOT IN (SELECT size_control FROM Foobar
UNION ALL VALUES (0)); -- handles 1
This will get the first open slot. Drop the MIN() and you get the
whole set. I am not usre how well this will perform, but you have a
covering index on size_control and the range is small.
SELECT MIN(size_control +1)
FROM Foobar
WHERE size_control +1
NOT IN (SELECT size_control FROM Foobar
UNION ALL VALUES (0)); -- handles 1
I thought that it is necessary to add "UNION ALL VALUES (0)" for first
"FROM Foobar" and last "UNION ALL VALUES (0)" is not necesary.
Like this .....
SELECT MIN(size_control +1)
FROM (SELECT size_control FROM Foobar
UNION ALL VALUES (0) -- handles 1
) S(size_control)
WHERE size_control +1
NOT IN (SELECT size_control FROM Foobar); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David.Tymon |
last post by:
>Description:
MySQL v4.1.0-alpha only allows a client to prepare a maximum of 254
statements. On the 255th mysql_prepare() call, a failure is returned
with no information returned by...
|
by: Jeff Boes |
last post by:
I'm sure this is a concept that's been explored here. I have a table
(fairly simple, just two columns, one of which is a 32-digit checksum)
with several million rows (currently, about 7 million)....
|
by: Kums |
last post by:
What is the maximum permissible size of a database? Is there any limitation.
What is the maximum # of tablespace's allowed in a database?
Thanks for your response.
|
by: shsandeep |
last post by:
What is the query to obtain a list of all the tables having the maximum
number of rows in descending order?
Cheers,
Sandeep.
|
by: phytorion |
last post by:
Does anyone know if there is a maximum number of rows you can have in on access table? I've been trying to run and append but it errors out every time it tries to append the rows from the query it...
|
by: =?Utf-8?B?U2hhcm9u?= |
last post by:
I'm using the VScrollBar and set it as follow:
m_vScrollBar.Minimum = -19602;
m_vScrollBar.Maximum = 0;
m_vScrollBar.SmallChange = 1;
m_vScrollBar.LargeChange = 1089;
m_vScrollBar.Value =...
|
by: David Greenberg |
last post by:
Hello
I am running a DTS (Sql 2000) and transfering data from an SqlServer
database to an Ingres database.
I am transfering 153k rows.
Execution fails with the error message:
"The number of...
|
by: enrique |
last post by:
Does anyone know what the upper limit is to the number of rows you can
dynamically add to an HTML table, using Javascript? I tried to make a
table consisting of over 74,000 rows and Firefox stops...
|
by: SjaakBanaan |
last post by:
Hey all,
I have a question that ought to be simple but has given me headaches for a while.
I have a table with contact email addresses, say.
T
ID ContID Priority Emailaddress...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |