• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

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

0
XK8ER
Asked:
XK8ER
  • 3
  • 2
1 Solution
 
Dan CraciunIT ConsultantCommented:
Create an unique key on (itockSymbol, iwhen)

HTH,
Dan
0
 
XK8ERAuthor Commented:
like this?

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

Open in new window

0
 
Dan CraciunIT ConsultantCommented:
ALTER TABLE EURJPY ADD UNIQUE (itockSymbol, iwhen);
0
 
XK8ERAuthor Commented:
it does the exact same thing
0
 
Dan CraciunIT ConsultantCommented:
Yup. But you'll find it's easier to read if you stick to the conventions: all SQL code is uppercase, the rest is lowercase.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now