PDA

View Full Version : mysql index question


centenial
05-14-2009, 08:14 PM
Hi,

I have a table


CREATE TABLE processes
(
process_id int primary key,
process_name tinytext,
process_type varchar(10),
gallery_id int
);


The `process_type`field has two possible values:

Task1


Task2


Only one instance of "Task2" can run on a gallery at a time. Task1 cannot run on a gallery that is currently being used by Task2. Multiple instances of Task1 can run on the same gallery. I want to create an index that will handle this logic for me, so that if I try to insert into the table, it will return false should there be a conflict.

Is it possible to do this with unique indexes?

abduraooft
05-15-2009, 10:08 AM
CREATE TABLE processes
(
process_id int primary key,
process_name tinytext,
process_type varchar(10),
gallery_id int(11),
unique key (`process_name`,`process_type`)
);
The `process_type`field has two possible values:

* Task1

* Task2
Then it's better to use a filed type of tinyint to store values 1 or 2, instead of a lengthy varchar filed.