Solved

mysql structure

Posted on 2014-03-12
5
324 Views
Last Modified: 2014-03-12
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
Comment
Question by:XK8ER
  • 3
  • 2
5 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39924436
Create an unique key on (itockSymbol, iwhen)

HTH,
Dan
0
 
LVL 1

Author Comment

by:XK8ER
ID: 39924455
like this?

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

Open in new window

0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39924461
ALTER TABLE EURJPY ADD UNIQUE (itockSymbol, iwhen);
0
 
LVL 1

Author Comment

by:XK8ER
ID: 39924508
it does the exact same thing
0
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39924520
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question