将表的所有列复制到具有不同列顺序的另一个表中 [英] copy all columns of a table in another table having different order of columns

查看:60
本文介绍了将表的所有列复制到具有不同列顺序的另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1 ...产品(pname,pdesc,数量)
2 ... product1(pname,img1,img2,pdesc,qty)
实际上,根据需要添加了另外两个(img1,img2)列,因此新表创建了产品

已经尝试过了

1... product (pname, pdesc, qty)
2... product1(pname, img1, img2, pdesc, qty)
actually there are two more (img1, img2) columns added as required, so new table created product

have tried this out

insert into product1 (pname, qty, pdesc)
select pname, qty, pdesc from product



也许它包含错误的代码,(对SQL的了解很少)

因此,请帮我一个忙,然后再次重写... ...



maybe it contains errorful code, (little lack of knowledge in sql)

so just do me a favor, and rewrite it again... please

推荐答案

如果img1img2是必填字段,请在这些字段中添加任何内容.

If img1 and img2 are required fields, add anything to these fields.

INSERT INTO product1 (pname, qty, pdesc, img1, img2)
SELECT pname, qty, pdesc, 0 AS img1, 0 AS img2
FROM product



如果接受可为空的值,请尝试以下查询:



If nullable values are accepted, try this query:

INSERT INTO product1 (pname, qty, pdesc, img1, img2)
SELECT pname, qty, pdesc, NULL AS img1, NULL AS img2
FROM product


查询看起来正确-检查列的类型.
The query looks correct - check the types of the columns.


这篇关于将表的所有列复制到具有不同列顺序的另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆