You can make a table's primary key a field of type ENUM
. For example:
CREATE TABLE test (
id enum('1','2') NOT NULL,
domain varchar(50) NOT NULL,
primary key (id));
When you update it you have to explicitly set the ID to "", "1", or "2".* It can't be null and there can only be one record with each ID. The domain is still stored in the domain
field, so hopefully whatever external system is querying this database won't have any problems getting the results it wants.
If you want to replicate the current restriction that domain names have to be unique, you could also add unique key (domain)
.
* note that the empty string is allowed (and not the same as NULL) because enum is actually a type of string. So you'd specify two permitted ID values in order to have three total.
Alternately: What are you trying to achieve / prevent here? Is there some automated process that might add records to the table? Are you trying to make sure that you don't accidentally do it, or that someone who hijacks your account can't do it?
If the process that might insert records is running on your user, you could put your three records into the table and then take away INSERT privileges from yourself. You'd still be able to alter the existing records but you wouldn't be able to add any more unless you explicitly re-granted the ability.