Search code examples
mysqlrowrestriction

Is it possible to restrict a table to have only one record in mysql?


Hi I'm a totally newbie in web development area. I want to create a table for admin login that has only one record (because there is only one admin). I want to know is it possible to set MySQL somehow to restrict a special table to have only one record?


Solution

  • You can set up a trigger (to be specific, an Insert trigger) that counts the records and, if count is more than 1, it does not allow the insert operation.

    Check out http://dev.mysql.com/doc/refman/5.0/en/insert.html and set up your logic accordingly.