473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to write the trigger to update 2 tables

Dear all,
I have 2 tables,

1.lv_data,
it has the following fields,
emp_name tot_days
guru 18



2.leave_data
it has the following fields,
emp_name From_date to_date no_of_days remaining_days
guru 02/05/2012 03/05/2012 2

In second table if the data is inserted ,
the no_of_days will be automatically calculated (from to_date - From_date)+1,

Here I need to write the trigger to update the remaining_days column,

In first table for all emp_name tot_days is 18 days,
so in second table whenever the record is inserted,
the remaining_days should be calculated like this,

remaining_days := tot_days - no_of_days and this(calculated) value should be updated in tot_days column in first table(lv_data),

Sample Example:
Expand|Select|Wrap|Line Numbers
  1. emp_name tot_days
  2. guru       18
  3.  

2.leave_data
Expand|Select|Wrap|Line Numbers
  1. emp_name   From_date   to_date   no_of_days   remaining_days
  2. guru       02/05/2012  03/05/2012    2            16
  3.  
Now the first table should be updated like,
Expand|Select|Wrap|Line Numbers
  1. emp_name tot_days
  2. guru       16
  3.  
  4.  
So I need to update 2 tables,
can someone help me to update these 2 tables through TRIGGER?

Thank you,
Regards,
gurujothi
May 2 '12 #1

✓ answered by Luuk

I think you should not store 'no_of_days' in your second table, but simply calculate it when needed.

1 1884
Luuk
1,047 Expert 1GB
I think you should not store 'no_of_days' in your second table, but simply calculate it when needed.
May 19 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: m3ckon | last post by:
Hi there, I'm a little stuck and would like some help I need to create an update trigger which will run an update query on another table. However, What I need to do is update the other...
1
by: Pesko S | last post by:
Hi, Could anybody just point me in a direction where I can find information on how the heck I can update a database with relational data from an XML file. I use stored procedures to insert...
3
by: beer | last post by:
Hello All I'm running 7.3.4-1 on a RH9 box. I'm having a problem with a trigger that seems to execute without actually performing the update that it should. The update returns true everytime...
1
by: Simon | last post by:
Hi all... I've got an editable datagrid in my application. Clicking "edit" enables those fields to be editted, and then clicking Update triggers my code to do the update on the database. I...
3
by: m.errami | last post by:
Hello all I have a small application for which I would like to write an update manager. I assume that the basics of it is to compare versions of the user's current application and a new one store...
9
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger,...
1
by: suvarna10 | last post by:
plz help me, I have two databases,I have to write trigger on one database in such a way that,data entered in one database should be visible in another database.
1
by: Swan | last post by:
Plz tell me how to write trigger in sql server 2005.Is there any special syntax for it?It's different from sql server 2000.Thanking you!
1
by: SKODA | last post by:
Hi, Could someone help me in knowing how to update tables in MS Access with data available on a website? I mean the functionality similar to refresh available in MS EXCEL where the data is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.