SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 auto editing table when entering on other table??
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dhh166
Starting Member

2 Posts

Posted - 06/20/2012 :  06:27:48  Show Profile  Reply with Quote
Hello All,
I have a table for 'products', and table for 'sold' which I want to store the sold products, I want the 'qantity' column for'products' table to be edited automatically when I put value for 'quantity' col of 'sold' table
ex: I have 10 pens and I sold 4 pens, when I record 4 pens in 'sold' table I want 'quantity' of 'products' to change automatically to '6'

TG
Flowing Fount of Yak Knowledge

USA
5500 Posts

Posted - 06/20/2012 :  13:56:19  Show Profile  Reply with Quote
It's really not a good design to try to maintain an [inStock] quantity column right in your product table. One way to mimic an inventory system is to present the real-time quantity only when you need to present it - by returning the (sum of items purchased) minus the (sum of items sold). The code for that can be in a function or stored procedure.

But to answer your question you could achieve what you described by performing the update to your [product] table from within a trigger on your [sold] table.

Be One with the Optimizer
TG
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000