Solved

mysql structure

Posted on 2014-03-12
5
321 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now