1

I am making a project on the online shopping site. there i am having on table for product details and other for stock details

the two tables are like this

ProductInfo
Column Name   Data Type   Constraint
ProductID     Int             Primary key , auto increment
ProductName   Varchar(100)  
SubCategoryID Int             Foreign key with ProductSubCategory
CompanyID     Varchar(20)     Foreign key with CompanyInfo
Price         Float 
Quantity      Int   
Description   Varchar(1000) 

ProductStock
Column Name Data Type     Constraint
StockID     Int         Primary key,auto increment
ProductID   Int         Foreign key with ProductInfo
Quantity    Int 
StockType   Varchar     Check(‘IN’,’OUT’)   
StockDate   Datetime

now initially i have kept the value of quantity of productinfo = 0 and want increment or decreement it on the basis of value of quantity of ProductStock depending upon StockType

If stock is 'In' then increment the quantity of productinfo by the number=value of quantity of ProductStock

If stock is 'Out' then decrement the quantity of productinfo by the number=value of quantity of ProductStock

What query should i made to made this operation?

4

2 回答 2

1

使用触发器“AFTER INSERT”来递增递减所需的值。

http://msdn.microsoft.com/en-us/library/ms189799(v=sql.100).aspx

于 2013-07-23T09:46:45.440 回答
0

尝试这个,

当您在 ProductStock 表中插入产品时,您只需要更新 ProductInfo 表。当 ProductStock 表中的库存减少时,只需更新 productInfo 表中的列名 Quantity。为此,匹配两个表上的 ProductID。

于 2013-07-23T09:54:17.247 回答