how to create trigger in SQL server using two tables to find stock quantity I have two table sales and purchase. I want to create a trigger which stores final quantity in stock table by subtracting sales table sold quantity from purchase table. 

There is kikkat as a name n quantity are 10, 15 respectively and both quantities should be subtracted from purchase quantity table and it should be saved in the stock table.
Instead of creating a trigger I would suggest you to create a new column in the purchase table which will be a computed column.

Before creating it, create a scalar function which will accept productname or productid and returns int. Inside it, write a query to find the total from sales for that particular row (by passing productname or id) and subtract it from purchase's quantity for that product.

If purchase can contain multiple entries for a particular product then create a separate table Stock and have columns as ID, ProductName\Id, stockQuantity (which will be a computed column as explained above).