通过sql查询复制行

时间:2014-02-08 06:12:51

标签: mysql sql batch-insert

我试图通过sql查询插入多行 场景是这样的: 针对1 testID有多个属性,我希望将一个测试的属性复制到另一个测试,方法是给出TestID这里是我正在尝试的查询但它根本不起作用

INSERT INTO dc_tp_attributes
(Attribute_name,acronym,active,description,testId,
subdepartmentid,
DOrder,Attribute_type,D_A_formula,D_A_formula_desc,
Linesno,DefaultValue,interfaced,ClientID,Enteredby,
Enteredon,drived,parentid,heading,print,interfaceid)

select Attribute_name,acronym,active,description,
635,subdepartmentid,DOrder,Attribute_type,D_A_formula,
D_A_formula_desc,Linesno,DefaultValue,interfaced,
ClientID,Enteredby,Enteredon,drived,parentid,
heading,print,interfaceid
FROM dc_tp_attributes
Where testid=877

这里我将testID=877的属性复制到testID=635,ID 877的测试有10个属性,testID 635的测试只有1。 有一个AutoIncrement Primery Key Named命名的AttributeID,错误是

"Field 'AttributeID' doesn't have a default value"

1 个答案:

答案 0 :(得分:2)

SELECT

中删除额外的括号
INSERT INTO dc_tp_attributes
(Attribute_name,... interfaceid)

select Attribute_name, ... interfaceid
FROM dc_tp_attributes
Where testid=877