Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
hirani_prashant
Yak Posting Veteran
93 Posts |
Posted - 2008-05-09 : 02:17:10
|
| i do have my 'Product' TABLE IN DATABASE 'ABC'Product TABLE OUTPUTPRODUCT_CODE PRODUCT_TYPE PRODUCT_DESC PRODUCT_ID PRODUCT_GROUP_CODE6001 computer NULL ENVD 146002 keyboard NULL ENVD 14 6003 mouse NULL ENVD 146004 cables NULL ENVD 146005 processor NULL ENVD 14AND 'Product_Mst' TABLE IN DATABASE 'XYZ'Product_Mst OUTPUTPROD_CODE Prod_Ver PROD_TYPE PROD_DESC PROD_ID PROD_GRP_CODE6001 0 computer NULL ENVD 146002 0 keyboard NULL ENVD 14 6003 0 mouse NULL ENVD 146004 0 cables NULL ENVD 146005 0 processor NULL ENVD 14Now i want TO CREATE TRIGGER such that every updation in Product TABLE will UPDATE the appropriate record IN Product_MstFOR example IF i fire below query IN ABC DatabaseUPDATE ProductSET PRODUCT_DESC = 'Available' WHERE Product_Code = 6001Then the OUTPUT OF the Product_Mst shoub be..Product_Mst OUTPUTPROD_CODE Prod_Ver PROD_TYPE PROD_DESC PROD_ID PROD_GRP_CODE6001 0 computer NULL ENVD 146001 1 computer NULL ENVD 146002 0 keyboard NULL ENVD 14 6003 0 mouse NULL ENVD 146004 0 cables NULL ENVD 146005 0 processor NULL ENVD 14Means i want to increment the version by 1 and Insert that records into Product_Mst Table at every updation.I hope i am clear with my question.RegardsPrashant Hirani |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-09 : 09:42:40
|
| [code]CREATE TRIGGER MyTrigger ON ABC..ProductAFTER UPDATE ASINSERT INTO XYZ..Product_MstSELECT pm.PROD_CODE, pm.Prod_Ver+1,pm.PROD_TYPE,pm.PROD_DESC,pm.PROD_ID,pm.PROD_GRP_CODEFROM XYZ..Product_Mst pmINNER JOIN INSERTED iON i.PRODUCT_CODE=pm.PRODUCT_CODEGO[/code]and if PRODUCT_CODE is an identity column, you need enable identity insert on Product_Mst table usingSET IDENTITY_INSERT XYZ..Product_Mst ON and set it to off after insert. |
 |
|
|
|
|
|