mysql - Populate table with all foreign keys from other table's primary key -


I am working on a Django application and created a new table tblA Is the key that is linked to the primary key of tblb .

Now there are many entries in ( so already many primary keys) in tblB .

I will run a SQL query that will copy the related key in the tblA inside tblb and enter a new row for each primary key with default values I

I hope I was clear enough!

You have forgotten to paste your table structure .. I am considering it as below-

tblA (aCol1_PK (primary key), acol2ddc (description)

Take an example of just two columns as of now.

tblB (bCol1, bCol2, bCol3_FK (foreign key))

now suppose that you have default values ​​-

bCol1 - "B_Col1_default_val" bcol2 - "B_Col2_default_val"

For this situation if you want to insert lines for p_key from table A, which is not present in table B. If you do not have the table You can try the question -

 Insert  in TBB (col1, col2, col3) ('b_col_default_val', 'b_col_default_val', 'tbla to acol1_pk, where a.acol1_pk is not (BBC3 BF to Teab If you want to insert a line for all the primary key values ​​present in Table A, then enter  
  in TLBB (col1 , Col2, col3) ('b_col_default_val', '  

I hope this will help you. You can ask / comment if you need any explanation.

Comments