sql问题

awinder 2004-01-09 01:33:37
如下sql语句为什么会出问题:
create table t1 (a int,b int)
select * into #t2 from t1
alter table #t2 add c int
alter table #t2 drop column c
insert into t1 select * from #t2

报告列值与表定义不匹配
如果再alter table 后面加上go 语句在查询分析器里可以执行,但是我在程序里面无法使用go语句,应该怎么解决?
...全文
46 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunshareforever 2004-01-09
  • 打赏
  • 举报
回复
create table t1 (a int,b int)
select * into #t2 from t1
alter table #t2 add c int
alter table #t2 drop column c

insert into t1
exec('select * from #t2')
awinder 2004-01-09
  • 打赏
  • 举报
回复
谢谢,我去试试
zjcxc 元老 2004-01-09
  • 打赏
  • 举报
回复
--这样就行了.
create table t1 (a int,b int)
select * into #t2 from t1

exec('alter table #t2 add c int')
exec('alter table #t2 drop column c')

insert into t1 select * from #t2
playyuer 2004-01-09
  • 打赏
  • 举报
回复
go 当然不能用于 programe
pengdali 2004-01-09
  • 打赏
  • 举报
回复
都可以实现
pengdali 2004-01-09
  • 打赏
  • 举报
回复
或:


create table t1 (a int,b int)
select * into #t2 from t1
exec('alter table #t2 add c int')
exec('alter table #t2 drop column c')
exec('insert t1 select * from #t2')
pengdali 2004-01-09
  • 打赏
  • 举报
回复
create table t1 (a int,b int)
select * into #t2 from t1
alter table #t2 add c int
alter table #t2 drop column c
exec('insert t1 select * from #t2')

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧