Relationship between tables

1

I have a certain table already created and populated:

CREATE TABLE 'formulario' (
  'id' int(4) NOT NULL AUTO_INCREMENT,
  'nome' varbinary(50) DEFAULT NULL,
  'carteira' varchar(30) NOT NULL,
  'tipo_ocorrencia' varchar(13) NOT NULL,
  'contato' varchar(20) DEFAULT NULL,
  'tel' varchar(50) DEFAULT NULL,
  'mensagem' text NOT NULL,
  'data' varchar(10) NOT NULL,
  'hora' varchar(8) NOT NULL,
  PRIMARY KEY ('id')
) ENGINE=MyISAM AUTO_INCREMENT=3744 DEFAULT CHARSET=utf8;

I'm creating this table now:

CREATE TABLE 'preformulario' ( 
'id' INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
'r1' VARCHAR( 3 ) NOT NULL ,
'r2' VARCHAR( 160 ) NOT NULL ,
'r3' VARCHAR( 160 ) NOT NULL ,
'r4' VARCHAR( 160 ) NOT NULL ) ENGINE = MYISAM;

I need to export a table that matches the two tables above! The user will inform the data of the preformulario table and then begin to inform the data of the formulario table. As I explained, the formulario table is already populated ... Your ID is in 3744.
I have little ... Almost nothing, experience with MySQL. I need to know if I need to create a third table by reconciling the two I mentioned or is there a solution in my PHP that already matches this data?

    
asked by anonymous 20.12.2016 / 21:41

2 answers

0

You do not need a third table, I've created a view or a proc or even a select that lists the data you want to show to the user in insert takes the id of the form table and insert in the other table. This is a many-to-many relationship

    
20.12.2016 / 22:14
0

list data from two related tables through a select, view, or procudure this to display to the user. In this select you will get the id of the formulario table which is what you need to do insert in the preform table ' This is usually the way to do it.

    
20.12.2016 / 23:23