Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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