Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

I am asking this question because of this Stack Overflow answer

Thanks!

like image 251
benjisail Avatar asked Jan 17 '11 16:01

benjisail


1 Answers

CREATE TABLE `myTable` (
  `id` enum('1') NOT NULL,
  `MyValue1` int(6) DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='The ENUM(''1'') construct as primary key is used to prevent that more than one row can be entered to the table';
like image 93
John Avatar answered Oct 20 '22 03:10

John