Alex Rivera | Logout

How can I ensure that there is one-and-only-one row in DB table?

Asked 2011-01-17T16:03:07.450
14

I would like to ensure that my MySQL table myTable has one-and-only-one row.

I need to be able to Update this row but Insert and Remove should be not possible.

I am asking this question because of this answer to How to create a "unique" constraint on a boolean MySQL column?.

Edit
Report

2 Answers

1

Try this:

CREATE TABLE foo (x INT NOT NULL PRIMARY KEY CHECK (x = 1), col1 INT NOT NULL, col2 INT NOT NULL);
answered 2011-01-17T16:17:24.173
0

If your database is set to 'strict' mode, you can create a table like this one:

create table foo (id enum('SYSROW') not null, (other column definitions) primary key (id));

answered 2011-12-14T01:58:07.427

Your Answer