Solved

mysql structure

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

Join & Write a Comment

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 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

18 Experts available now in Live!

Get 1:1 Help Now