Merge, in table in mysql

0

I'm not good at describing, so I'll leave an example.

I have this structure.

CREATE TABLE IF NOT EXISTS 'Teste' (
  'ID' int(11) NOT NULL AUTO_INCREMENT,
  'Var_1' varchar(255) NOT NULL,
  'Var_3' varchar(255) NOT NULL,
  'Var_5' varchar(255) NOT NULL,
  'Var_7' int(11) NOT NULL,
  'Var_9' int(11) NOT NULL,
  'Var_11' varchar(255) NOT NULL
  PRIMARY KEY ('ID')
)

Now I have this new structure:

CREATE TABLE IF NOT EXISTS 'Teste' (
  'ID' int(11) NOT NULL AUTO_INCREMENT,
  'Var_1' varchar(255) NOT NULL,
  'Var_2' varchar(255) NOT NULL,
  'Var_3' varchar(255) NOT NULL,
  'Var_4' varchar(255) NOT NULL,
  'Var_5' varchar(255) NOT NULL,
  'Var_6' varchar(255) NOT NULL,
  'Var_7' int(11) NOT NULL,
  'Var_8' int(11) NOT NULL,
  'Var_9' int(11) NOT NULL,
  'Var_10' int(11) NOT NULL,
  'Var_11' varchar(255) NOT NULL
  PRIMARY KEY ('ID')
)

How do I override the old table with the new one, I have no idea where to start, I would like it to detect itself and join automatically, how do I detect it in PHP? Give me a light I'll turn around. Thanks ^^

    
asked by anonymous 03.04.2016 / 03:27

1 answer

0

Well from what I understand then you do not want a 'merge' and yes you want to change your table ... 'Merge' would merge two tables into one with distinct data into a new one, but in your case you want to get a table that already exists and "expand" it with more fields without losing the data that already exists, if this is simple just use the command ALTER TABLE and add the fields before or after, in your case would be:

ALTER TABLE 'teste' ADD 'Var_2' VARCHAR(255) NOT NULL AFTER 'Var_1';
ALTER TABLE 'teste' ADD 'Var_4' VARCHAR(255) NOT NULL AFTER 'Var_3';
ALTER TABLE 'teste' ADD 'Var_6' VARCHAR(255) NOT NULL AFTER 'Var_5';
ALTER TABLE 'teste' ADD 'Var_8' VARCHAR(255) NOT NULL AFTER 'Var_7';
ALTER TABLE 'teste' ADD 'Var_10' VARCHAR(255) NOT NULL AFTER 'Var_9';
    
03.04.2016 / 07:51