Is there any way to limit the maximum number of rows when I create a table in Oracle?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If the table has a numeric key, you could add a check constraint that states that the key does not exceed a specific value:
ALTER TABLE turnip
ADD CONSTRAINT check_turnip_id
CHECK (turnip_id <= 50)
/
回答2:
You could create a statement trigger "BEFORE INSERT" and check there the nubmer of rows.
CREATE OR REPLACE TRIGGER BI_MY_TABLE
BEFORE INSERT ON MY_TABLE
DECLARE
CountRows NUMBER;
BEGIN
SELECT COUNT(*)
INTO CountRows
FROM MY_TABLE;
IF CountRows > 100 THEN
RAISE_APPLICATION_ERROR(-20001, 'Only 100 records are allowed');
END IF;
END;
/
However, this trigger does not work properly in a multi-user environment.