How to allow only one row for a table?

后端 未结 3 1548
甜味超标
甜味超标 2021-02-18 18:18

I have one table in which I would like only one entry. So if someone is trying to insert another row it shouldn\'t be allowed, only after someone deleted the pr

3条回答
  •  無奈伤痛
    2021-02-18 19:15

    You should create a ON BEFORE INSERT trigger on this table. On the trigger, call a procedure that checks count(*) and when the count is 1, it returns an exception message to the user otherwise the insert is allowed to proceed.

    Check this documentation for an example.

提交回复
热议问题