Link to home
Start Free TrialLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on

mysql structure

Hello,
I have this mysql structure that its working fine for me and very simple..
I would like to know if its possible to create something so that it doesn't allow duplicates on (itockSymbol with iwhen) which is a timestamp

for example there is an insert USD and 1394647007306
and again another insert insert USD and 1394647007306 but dont allow it as it is a dup.
but if its AUD and 1394647007306 then its okay.
how can I do this?

CREATE TABLE IF NOT EXISTS `EURJPY` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `itockSymbol` varchar(40) DEFAULT NULL,
  `iwhen` varchar(20) DEFAULT NULL,
  `ibuyValue` varchar(20) DEFAULT NULL,
  `isellValue` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
)  ;

Open in new window

Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Create an unique key on (itockSymbol, iwhen)

HTH,
Dan
Avatar of XK8ER

ASKER

like this?

alter table EURJPY add unique index(itockSymbol, iwhen);

Open in new window

ALTER TABLE EURJPY ADD UNIQUE (itockSymbol, iwhen);
Avatar of XK8ER

ASKER

it does the exact same thing
ASKER CERTIFIED SOLUTION
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial