Log in

View Full Version : Quick MYSQL question...


Kolo
09-04-2003, 05:58 PM
How would you phrase a CREATE statement to state the following...

I have 2 columns, each column can have duplicate values, but no rows can have both duplicated...hrm..example:
| I1| I2| Data
| 1 | 2 | Data
| 1 | 3 | Data
| 2 | 2 | Data
| 3 | 1 | Data
| 3 | 2 | Data

but I could not add (1 | 3) again. I1 and I2 are the keys in this example. I've been searching the internet for a response to this but keep coming up with syntax formats and whatnot. I would prefer a plain english response :)

Thanks in advance...

Kolo
09-04-2003, 06:14 PM
I think I might have gotten it, but I want to be sure this is the correct method of doing this :/

CREATE TABLE `blah` (
`ID_1` int(11) unsigned NOT NULL default '0',
`ID_2` int(11) unsigned NOT NULL default '0',
`data` varchar(50) NOT NULL default '',
PRIMARY KEY (`ID_1`,`ID_2`),
UNIQUE KEY `Unique` (`ID_1`,`ID_2`)
);

Again, if you can provide me insight on this, Thanks!