Hii i am building a financial database. And I have data for each stock for all the days. I want to avoid multiple entry of a stock for the same timestamp in the database. For eg I dont want to have the data for google on 30 jun 2010 twice. How can i do this

Recommended Answers

All 2 Replies

Not sure how you're database looks, but you could add a unique index on the date column and the stock id.

Hi

>> I want to avoid multiple entry of a stock for the same timestamp in the database.

Then put a timestamp attribute in the primary key, for example ts:

CREATE TABLE yourtable (
ts TIMESTAMP NOT NULL,
a VARCHAR(20),
PRIMARY KEY(ts)) ENGINE = InnoDB;

Resolution of ts is approximately some milliseconds. Do not forget to choose the right ENGINE and if possible, try to avoid ID INT NOT NULL AUTO_INCREMENT.

-- tesu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.