At 21:56 -0500 7/22/03, Greg Macek wrote:
Hello,

I have a strange question. I'm in the design phase for a table and was
wondering if it's possible in MySQL to force a pair of fields in a
record to be unique within the table. I would like it to look like this:

user_id
job_id

What I'd like to do is never have the same user_id and job_id paired up
paired together more than once. Maybe I'm missing a better way to setup
this table. If I am, please let me know. Thanks.

Create a composite PRIMARY KEY or UNIQUE index on both columns.


ALTER TABLE tbl_name ADD PRIMARY KEY (user_id, job_id);

or

ALTER TABLE tbl_name ADD UNIQUE (user_id, job_id);

You can use a PRIMARY KEY only if both columns are NOT NULL.

--
Paul DuBois, Senior Technical Writer
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

Are you MySQL certified? http://www.mysql.com/certification/


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to