mysql - How to put multiple updates in a trigger? -


i hope can me here. using mysql + phpmyadmin , have 2 tables in problem.

table 1: accounts - id, account_name, website, etc. etc...
table 2: domains - id, domain_name, account_name

and inserted these queries 2 triggers.

before update
update domains, accounts
set domains.account_name = null
accounts.website != domains.domain_name

after update
update domains, accounts
set domains.account_name = accounts.account_name
domains.domain_name = main_accounts.website

with these, when update in accounts table, automatically remove account_name domains table , put new account_name if account updated.

images below show example.
tables not yet updated:
----------
accounts table
enter image description here

domains table
enter image description here ----------
----------
updated view.
----------
----------
accounts table
enter image description here

domains table
enter image description here

so, on second account table image, have changed domain , automatically, domains table has been updated. want make 1 trigger contain 2 update queries. don't know if it's possible because after complete this, may need know how update multiple different tables 1 trigger. reason why ask because need assign account name each sub-tables in use. example, main table accounts table , sub tables needs updated are:
domains.account_name
ip_address.account_name
phones.account_name
payments.account_name

so, don't know if it's possible update sub-tables under column "account_name" when main table "accounts" updated.

thank you. hope question clear. :d :d

you can group multiple statements trigger begin , end.

example:

delimiter $$  create trigger my_trigger before insert on accounts each row begin     // statement 1     update domains     set domains.account_name = accounts.account_name     domains.domain_name = main_accounts.website;     // statement 2     update another_table     set another_table.column_name = accounts.account_name     another_table.domain_name = accounts.some_column;     // more update statements end$$ 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -