I have a table set up on a mysql database called “access” with three columns called:
rights_id, (PRIMARY KEY)
username,
name,
In the rights_id column the user can only input 3 different values (“1″,”2”, or “3”) 1 means resource, 2 means manager, and 3 means administrator. my problem occurs when there are more than one row with the same rights_id (ie: more than one administrator).It displays an error that tells me i can’t have a duplicate entry for the PRIMARY KEY… i was wondering if there was a way to supress this error and allow me to do this? im using vb.net to interact with my MYSQL database running on a Windows 7 OS. Thanks!
I’m not sure what “name” means in that table. If it’s safe for me to ignore it . . .
If each username can have only one “rights_id”, then the primary key should be username. If each username can have more than one “rights_id”–if user Catcall can have rights_id 1 and 2 at the same time–then your primary key should be the pair of columns (rights_id, username).
Since MySQL doesn’t enforce CHECK constraints, you should have a separate table of rights id numbers, containing three rows.
Then you can set a foreign key constraint that will prevent any numbers besides those three from appearing in the table named “access”. Something like