mysql - Limit the number of records a table can have -


i created table, master-domain. table should have 3 records. how can limit mysql database allow no more number of records? there specific sql command acomplish this?

this current sql:

create table `mydatabase`.`master-domain` ( `domain` varchar( 50 ) not null comment 'domain name', primary key ( `domain` ) ) 

ps. have godaddy , includes phpmyadmin, in addition mysql databases.

you can make table's primary key field of type enum. example:

create table test (     id enum('1','2') not null,      domain varchar(50) not null,      primary key (id)); 

when update have explicitly set id "", "1", or "2".* can't null , there can 1 record each id. domain still stored in domain field, whatever external system querying database won't have problems getting results wants.

if want replicate current restriction domain names have unique, add unique key (domain).

* note empty string allowed (and not same null) because enum type of string. you'd specify 2 permitted id values in order have 3 total.


alternately: trying achieve / prevent here? there automated process might add records table? trying make sure don't accidentally it, or hijacks account can't it?

if process might insert records running on user, put 3 records table , take away insert privileges yourself. you'd still able alter existing records wouldn't able add more unless explicitly re-granted ability.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -