mysql - Inserting data into table SQL server -
if have 2 tables , table 1 has primary key(userid) autoincrement , table 2 has foreign key(userid) table 1's (userid)
when insert new row table 1 first row have userid = 1
then if insert again, userid = 2.
so how go keeping table 2's userid same when inserting in table 1. instance, in table 2, adding password table.
my question should add autoincrement table 2(userid) , insert new value both tables when create user or there way?
you have manually insert data correct id in table2. there no such built-in functionality in mysql.
the algorithm follows:
- insert row in table1.
- get id of new row.
- insert row new id in table2.
Comments
Post a Comment