Create a table copy

0

Greetings. I have a table (basic_data), when generating a "new project", each project inherits basic_data. But when the user wants to edit these, the ideal is that these modifications are in a table "data_basicos_editables", that is to say where you can make changes without damaging the table of data_basicos.

Ways to handle the problem:

  • Create a copy of data_basic to data_basic_editables and in this perform x opeacion
  • A better idea or practice?

With this query I can create a table from another, but is there something like an INSERT?

CREATE TABLE table2 AS SELECT * FROM table1;

When the query is done with the above statements, it does not create a primary key and apart from this, I would need to add other columns and data to the table to create the relation fk_project id 1 to this copied data

PROCESS

Form is filled and these go to the "project" table, each project must have basic_data. It would be a bad practice to use the basic data to make modifications, therefore a new table should be created and this is related to each project and in this way make modifications.

    
asked by Alex Hunter 15.12.2017 в 15:54
source

1 answer

2
  

With this query I can create a table from another, but is there something like an INSERT?

     

on the other hand, being specific, how would you do to copy the data of a table and take it to another table already created?

I will limit myself to answer this portion of your more specific question. For this you can use the syntax INSERT INTO ... SELECT ... :

INSERT INTO tabla2 (col1, col2, ..., colN)
SELECT col1, col2, ..., colN
  FROM tabla1
    
answered by 15.12.2017 / 16:25
source