database - MYSQL Insert Data into table using Foreign Keys from different tables -


i have temporary table "teststepdump" created "load data local infile". temporary table contains data of different tables connected foreign keys in table testresult:

  1. teststepdump (dummyno, stationno, name, result)
  2. duttest (id, dutid, processtime)
  3. dut (id, dummynr)
  4. station (id, stationno)
  5. teststepname(id, name)
  6. teststepresult(duttestid,teststepid,result)

i´m trying way using stored procedure, error 1452:

sql fehler (1452): cannot add or update child row: foreign key constraint fails (database.teststepresult, constraint teststepresult_ibfk_1 foreign key (duttestid) references duttest (id) on delete cascade on update cascade)

begin declare dt_id int; select teststepresult.duttestid dt_id teststepresult inner join duttest on teststepresult.duttestid = duttest.id inner join dut on duttest.dutid = dut.id inner join station on duttest.stationid = station.nummer inner join teststepdump on teststepresult.id = teststepdump.id dut.dummynr = teststepdump.dummyno , station.nummer = teststepdump.stationno;  insert teststepresult (duttestid, teststepid, result)  select dt_id, teststepname.id, teststepdump.result  teststepdump inner join teststepname on teststepdump.name = teststepname.name  teststepname.name = teststepdump.name; terminate teststepdump; end 

for single insert stored procedure working me, want avoid "for" loop;:

begin  declare t_id int; declare tn_id int;  select teststepname.id tn_id teststepname   teststepname.name = name;  select duttest.id t_id duttest inner join dut on duttest.dutid = dut.id  inner join station on duttest.stationid = station.id dut.dummynr = dummyno ,  station.nummer = stationno;  if not t_id null , not tn_id null insert teststepresult (duttestid, teststepid, result)  values (t_id, tn_id, result); end if; end 

i solved problem !

begin insert teststepresult (duttestid, stepname, result)  select duttest.dutid, teststepdump.name, teststepdump.result  duttest inner join dut on duttest.dutid = dut.id inner join station on duttest.stationid = station.id inner join teststepdump on dut.dummynr = teststepdump.dummyno  dut.dummynr = teststepdump.dummyno , station.nummer = teststepdump.stationno; #truncate teststepdump;  end 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -