开发者

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

开发者 https://www.devze.com 2022-12-12 19:32 出处:网络
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 fla开发者_如何学Pyth

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 fla开发者_如何学Pythong.

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消