954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

hOW TO INSERT NEW RECORD IN SEC TABLE?

i want to insert new row in second table and this table connected to first table.
How can i do that?

dharam_05
Newbie Poster
22 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

By giving us some additional data like what is structure of these two tables?

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

There are two tables:
1) Emp table with fields.
Emp_id, Emp_name,Dept.
2) Salary table with fields.
Emp_id, Salary.

I want to insert new record in salary table, if i insert rec in salary table it should also update in first table.
How i can do this?

dharam_05
Newbie Poster
22 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

There is nothing to update in first table Emp_id what links both tables. So if you trying to get salary of an employee you either have already person's ID or you will find out through matching of employee name and department against Emp table. Once you get that ID then you can query salary table for that person salary

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

i dont want to fetch the records i just want to insert new rec in sec table's field so when i enter new Emp_id in salary table then this Emp_id should also be reflected in first table.

dharam_05
Newbie Poster
22 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

There is nothing to reflect in first table. In reality you do want to only update salary in salary table. If you start adding new salaries with same employee ID how do will you find what is that person actual salary from numerous records you will have?

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

Ya with the same Emp_id it will be ok but i wanta dd new Emp_id in sec table..
just want give more info like:

Emp table
Emp_id Emp_name
1 ABC
2 EFG

Salary table

Emp_id Salary
1 1000
2 2000

Now i want insert new rec in salary table with new Emp_id = 3 and salary = 3000;
I want Emp_id 3 should also reflect in first table as far as Emp_name concern it will null.
This is my Query.

Thanks

dharam_05
Newbie Poster
22 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

Anuone help on it...

dharam_05
Newbie Poster
22 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

There is option to use triggers, but so far I had no time to test how does it work, or execute 2 insert statements one after other with same Emp_id

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

yes i too thinking of trigger " after inserting in salary". but was not too sure...

dharam_05
Newbie Poster
22 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

Hello dharam if u know the concept of Primary and Foriegn key than it wil be very easy for u to maintain the things as you cant add any salary for an id that does not exist in parent table so rather than putting an trigger on it, it would be better if you use this concept.

AllieK
Newbie Poster
2 posts since Nov 2007
Reputation Points: 11
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You