insert into问题
TB1,字段date1,group1,code,quantity
TB2,字段date1,group1,code,quantity,no1(自增字段)
想把TB1的数据复制到TB2
insert into tb2 (date1,goup1,code,quantity) select (date1,goup1,code,quantity) from tb1
在SQL分析器中提示:服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: ',' 附近有语法错误。
请问表tb1如何COPY数据到tb2表?
作者: sunfor 发布时间: 2011-06-13
insert into tb2 (date1,goup1,code,quantity) select date1,goup1,code,quantity from tb1
作者: maco_wang 发布时间: 2011-06-13
TB2主键:date1,no1(自增字段)
作者: sunfor 发布时间: 2011-06-13
insert into tb2 (date1,goup1,code,quantity) select date1,goup1,code,quantity from tb1
作者: chuanzhang5687 发布时间: 2011-06-13
作者: chenhongjun0624 发布时间: 2011-06-13
insert into tb2 (date1, goup1, code, quantity) select date1, goup1, code, quantity from tb1
作者: xuam 发布时间: 2011-06-13
insert into tb2 (date1,goup1,code,quantity) select * from tb1
作者: fredrickhu 发布时间: 2011-06-13
TB2主键:date1,no1(自增字段)
insert into tb2 (date1,goup1,code,quantity)
select date1,goup1,code,quantity from tb1
服务器: 消息 515,级别 16,状态 2,行 1
无法将 NULL 值插入列 'no1',表 'tiancheng.dbo.salary_data';该列不允许空值。INSERT 失败。
语句已终止。
作者: sunfor 发布时间: 2011-06-13
TB2主键:date1,no1(自增字段)
insert into tb2 (date1,goup1,code,quantity)
select date1,goup1,code,quantity from tb1
服务器: 消息 515,级别 16,状态 2,行 1
无法将 NULL 值插入列 'no1',表 'tb1';该列不允许空值。INSERT 失败。
语句已终止。
作者: sunfor 发布时间: 2011-06-13
no1不能为NULL
作者: sunfor 发布时间: 2011-06-13
insert into tb2 (date1,goup1,code,quantity,null) select * from tb1试试
作者: chuanzhang5687 发布时间: 2011-06-13
TB2主键:date1,no1(自增字段)
no1不能为NULL
作者: chuanzhang5687 发布时间: 2011-06-13
这个提示"在关键字 'null' 附近有语法错误"
引用 9 楼 sunfor 的回复:
TB2主键:date1,no1(自增字段)
no1不能为NULL
把tb1加一个自增长键试试
tb1里有数据,加不了no1(自增字段)!
作者: sunfor 发布时间: 2011-06-13
作者: chuanzhang5687 发布时间: 2011-06-13
作者: chuanzhang5687 发布时间: 2011-06-13
但你tb2里面五个字段,tb1里面四个字段,只能查询出四个字段 nol 又不能为空
用户以前用的是表TB1,由于需要,现要把表TB2加一个NO1自增字段,这就要把TB1数据COPY过来用!
作者: sunfor 发布时间: 2011-06-13
SQL code
--删除 alter table tb2 drop column no1 --添加 alter table tb2 add no1 int identity (1,1) --重试 insert into tb2 (date1,goup1,code,quantity) select date1,goup1,code,quantity from tb1
作者: ap0405140 发布时间: 2011-06-13
SET IDENTITY_INSERT tb2 ON insert into tb2 (date1,goup1,code,quantity) select date1,goup1,code,quantity from tb1 --标明字段名 SET IDENTITY_INSERT tb2 OFF
作者: chuanzhang5687 发布时间: 2011-06-13
--删除 alter table tb2 drop column no1 --添加 alter table tb2 add no1 int identity (1,1) SET IDENTITY_INSERT tb2 ON insert into tb2 (date1,goup1,code,quantity) select date1,goup1,code,quantity from tb1 --标明字段名 SET IDENTITY_INSERT tb2 OFF
作者: chuanzhang5687 发布时间: 2011-06-13
作者: chuanzhang5687 发布时间: 2011-06-13