'is there any way to automate one table data insertion depending on another table data in MySQL

don't know if it's possible or not, but I'm wondering if I can automate the insertion of MySQL table2 depending on table1

Let's say I've two tables ( table1 and table2 ) in my database. and what I want is an automation, which will automatically create a new row in table2 with some default values whenever a new row is created in table1. so that I don't have to write insertion code for table2 in my PHP file

Don't know if I've made it enough clear. let me brief my table structure in a nutshell...

table1 :-

  • user_name ( unique )
  • user_email

table2 :-

  • user_name ( same as table1 )
  • is_account_active ( true as default )
  • invested ( 0 as default )
  • current_balance( 0 as default )

so whenever an account is created, I'm inserting new data both in table1 and table2. so I'm wondering if I can create the table2 in a specific way that whenever a new row is created in table1, table2 will automatically pull user_name from table1's new row and insert it in its own storage ( the rest of the column data are static. so I can set defaults for 'em )

[ NOTE: I need to keep 'em in two different tables as there'll be many columns in each table ]

<-- I know many of you'll ask for what I tried. but tbh I don't even have any idea what to try -->



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source