Reputation: 3
Is there any way to copy entire data from one table to another table?
Condition: without making these data to retrieve from one table and storing to array than saving to another table.
Reason according to me:
Upvotes: 0
Views: 2467
Reputation: 91
To copy data from one table and also all the dependent objects of the table, you use the following statements:
CREATE TABLE IF NOT EXISTS new_table LIKE existing_table;
INSERT new_table
SELECT * FROM existing_table;
From here: MySQL Copy Table With Examples
Upvotes: 4
Reputation: 15941
$results = DB::select( DB::raw("CREATE TABLE tbl_new AS SELECT * FROM tbl_old;'") );
I believe you will get what you want.
comment on this answer if you need more info
Upvotes: 0