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:

  1. insert row in table1.
  2. get id of new row.
  3. insert row new id in table2.

Comments

Popular posts from this blog

multithreading - Exception in Application constructor -

React Native allow user to reorder elements in a scrollview list -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -