将列从一个表复制到另一个表

时间:2022-10-21 23:42:05

I have 2 tables suppose TABLE_1 and TABLE_2. I have a,b,c columns in TABLE_1 and x,y,z columns in TABLE_2. I want to copy only table structure from TABLE_2 and add it to TABLE_1 so my final table TABLE_1 would be like a,b,c,x,y,z. How can I do this.

我有2个表,假设TABLE_1和TABLE_2。我在TABLE_1中有a,b,c列,在TABLE_2中有x,y,z列。我想从TABLE_2中仅复制表结构并将其添加到TABLE_1,因此我的最终表TABLE_1将类似于a,b,c,x,y,z。我怎样才能做到这一点。

I don't want to have alter table then have defination of each single column then add it to 'table_1'.

我不想让alter table然后对每一列进行定义,然后将其添加到'table_1'。

Is it possible to do in mysql with single query ??

有可能在mysql中使用单个查询吗?

2 个解决方案

#1


0  

No this is not possible in one query.

在一个查询中,这是不可能的。

You could however write a pure SQL procedure to do it (by inspecting the information_schema database), but this is not trivial, and probably not worth the hassle.

但是,您可以编写一个纯SQL过程来执行此操作(通过检查information_schema数据库),但这并非易事,可能不值得麻烦。

#2


0  

There are ways, sure, but if there's no relation between the tables, DON'T DO IT!

确实有一些方法,但如果表之间没有关系,请不要这样做!

It's no problem to have multiple tables, you know?

拥有多张桌子没问题,你知道吗?

And even if there is a relation, as long as it's not a 1:1 relation (not even then necessarily, depends...), I wouldn't recommend it either. I suggest you read up a bit on database design and normalization forms.

即使存在关系,只要它不是1:1的关系(甚至不是必然的,取决于......),我也不会推荐它。我建议你阅读一些数据库设计和规范化表格。

#1


0  

No this is not possible in one query.

在一个查询中,这是不可能的。

You could however write a pure SQL procedure to do it (by inspecting the information_schema database), but this is not trivial, and probably not worth the hassle.

但是,您可以编写一个纯SQL过程来执行此操作(通过检查information_schema数据库),但这并非易事,可能不值得麻烦。

#2


0  

There are ways, sure, but if there's no relation between the tables, DON'T DO IT!

确实有一些方法,但如果表之间没有关系,请不要这样做!

It's no problem to have multiple tables, you know?

拥有多张桌子没问题,你知道吗?

And even if there is a relation, as long as it's not a 1:1 relation (not even then necessarily, depends...), I wouldn't recommend it either. I suggest you read up a bit on database design and normalization forms.

即使存在关系,只要它不是1:1的关系(甚至不是必然的,取决于......),我也不会推荐它。我建议你阅读一些数据库设计和规范化表格。