Constrain a table to only 1 row

I needed a table that could only ever have one row – if anyone tried to insert a second row they’d get an error.

CREATE UNIQUE INDEX only_one_row_allowed ON mytable (1);

Testing it:

INSERT INTO mytable VALUES ('x');
ORA-00001: unique constraint (SCOTT.ONLY_ONE_ROW_ALLOWED) violated

New web site built with APEX: www.myhomecontents.com.au
Generating unique identifiers with “SELECT MAX(id) + 1”

Leave a Reply

Your email address will not be published / Required fields are marked *