A trigger cannot be called or executed; DBMS automatically fires the trigger as a result of a data modification to the associated table or tables. Triggers can be viewed as similar to stored procedures in that both consist of procedural logic and it is stored at the database level.
Illustration with an example
There are two database tables one for stock of items that contain stock of items and another for sale of items. Both tables have relationship.
(A) Table Stock (tbl_stock) :
|
Column Name |
Data Type |
Constraint/Description |
|
stock_id |
Int |
Identity(1,1) primary key |
|
Item_id |
Int |
Foreign key |
|
Stock |
Int |
Total stock of items |
(B) Table Sale(tbl_sale) :
|
Column Name |
Data Type |
Constraint/Description |
|
Sale_id |
Int |
Identity(1,1) primary key |
|
stock_id |
Int |
Foreign key |
|
Sale |
Int |
Total sale of items |

Raja TPosted Nov 27, 2015, 5:29 AM
Nice, Thanks for sharing
Lajapathy ArunPosted Jun 22, 2012, 1:46 PM
nice & simple :)