快速将列的副本添加到MySQL表

快速将列的副本添加到MySQL表

本文介绍了快速将列的副本添加到MySQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种快速的方法来复制表中的DATETIME列并为其赋予新的名称.

I need a fast way duplicate a DATETIME column in a table and give it a new name.

我的表中有一个名为myDate的列,名为myResults,我需要一个查询以在表中创建一个名为newDate的新列,该列具有与myDate列完全相同的数据.

I have a column named myDate in my table called myResults, I need a query to make a new column in the table called newDate which has the exact same data as the myDate column.

是否有比做一个明显的两步方法来创建新列,然后复制所有数据(这是一个大表,我正在寻找最快的方法)更快的方法?

Is there a faster way to do this than by doing the obvious 2 step approach of make a new column, and then copying all the data (it's a large table and I'm looking for the fastest approach)?

明显的解决方案:

 ALTER TABLE `myResults` ADD `newDate` DATETIME;
 UPDATE `myResults` SET `newDate` = `myDate`;

推荐答案

不幸的是,显而易见的解决方案是唯一的解决方案.

The obvious solution is the only solution, unfortunately.

但是请注意,通常您不应该在关系数据库中复制列.

However note that in general you shouldn't be copying a column in relational databases.

这篇关于快速将列的副本添加到MySQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 01:34