NewBie
NewBie

Reputation: 1

How can I update 2nd table is 1st table is updated in MySQL?

I am having two tables. For example one is Login and the other is calculation. In the login table I am having fields username and password. In calculation I am having username and flag.

Now when any user is added in the login table I want make entry for that user in calculation table also.

How can I proceed for this?

Upvotes: 0

Views: 87

Answers (2)

user210046
user210046

Reputation: 11

Why not have the flag in the Login table?

In MySQL you should be able to set a 'trigger' on the insert operation on the login table, that can do the second insert for you. See:

http://dev.mysql.com/doc/refman/5.0/en/triggers.html

You might want to handle deletes and/or updates (change of username?) in the same way.

Upvotes: 1

Elemental
Elemental

Reputation: 7521

Meder's answer above will certainly work but prehaps the strategy you are looking for involves triggers; this will allow you to automatically update other info when ever row on a specific table is inserted, updated or deleted.

You only have to create trigger once and then any insert from any source to your LOGIN tbale will also update your CALCULATE table.

My SQL Documentation details the statement here.

Upvotes: 0

Related Questions