tags:

views:

134

answers:

2

I have a table with products.

artID   artName stock order

1   cables *100 0
2   cables *1 75

What should I do to asociate these 2 rows and get the stock in sync. The provider sells the cables in bulks on 100 units, and the retail store sells then as unit. The idea is: when "cables *1" run nearly out of stock set the order row to 1 so the employees know they need to buy more cables. I have a relations table defining multiple types of relations between articles (if this server for something) Obviously this is a very simplified version of the db.

I'm working with php. But any language agnostic idea will serve.

+3  A: 

I think you should create a trigger on your table that will be fired on UPDATE and will change the value after updating first row.

Here's the docs of how to use triggers in MySQL.

RaYell
hows that for timing??? :-)
Koekiebox
Thanks RaYell. Same question to you. Do you know any in dept tutorial? this one from database design is a good start, but i know I will need something more, and the MySQL documentation serves only as reference.
The Disintegrator
There's plenty of tutorials in Google, just type: `MySQL trigger tutorial`
RaYell
+3  A: 

Have you considered using a trigger?

See

MySQL Trigger

and

Databasedesign-resource

Koekiebox
That was blitsig, if you know what I'm saying :P
Mr. Smith
I was afraid that the answer will be triggers. The thing is, triggers don't like me. I try to understand them, but they keep ignoring me. Do you know any in dept tutorial? this one from database design is a good start, but i know I will need something more, and the MySQL documentation serves only as reference.Thanks
The Disintegrator