H,
i Please find the query for the required logic
drop table shopname
Create Table shopname (shopid int identity(1,1) primary key,ShopName varchar(150))
Insert shopname values ('Poorvika')
Insert shopname values ('Univercell')
Create Table item (itemid int identity(1,1) primary key,itemName varchar(150))
Insert item values ('Mobile')
Insert item values ('Mp3Player')
Create Table Stock ( stockid int identity(1,1) primary key, shopid int foreign key references shopname(shopid),
itemid int foreign key references item(itemid), Stockremaining int)
Insert Stock values(1,1,10)
Insert Stock values(1,2,8)
Insert Stock values(2,1,3)
Insert Stock values(2,2,3)
create table salesdetails
(
salesid int identity(1,1) primary key,
shopid int foreign key references shopname(shopid),
itemid int foreign key references item(itemid),
dateofpurchase date)
CREATE TRIGGER salestrigoninsert on salesdetails
AFTER INSERT
AS
BEGIN
Declare @shopid int
Declare @itemid int
Select @shopid = shopid, @itemid=i.itemid from inserted i;
Update stock set Stockremaining = Stockremaining-1 where Shopid =@shopid and itemid = @itemid
END
Insert salesdetails values (1,1,'2013-10-04')
Select * from shopname
Select * from item
Select * from stock
Select * from salesdetails
Note: Table names are not exactly the same
Regards,Mahe...