简体   繁体   English

Laravel 5.4-将数据从一个表复制到同一数据库中的另一表

[英]Laravel 5.4 - copy data from one table to another table, in same database

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: 根据我的原因:

  1. running these entire database on localhost 在本地主机上运行这些数据库
  2. there are nearly avg 100k rows 平均有10万行
  3. retrieving to array is costly with respect to memory (don't care) but time (important, as entire db on localhost which process slowly) 就内存而言,检索到数组是昂贵的(无关紧要),但是相对于时间(重要,因为本地主机上的整个数据库处理缓慢)

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 从这里: MySQL复制表与示例

$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 如果您需要更多信息,请对此答案发表评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM