Solved

mysql structure

Posted on 2014-03-12
5
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 35

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 35

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 35

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

726 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