insert into select 的问题

diaokkcool 2010-08-21 11:34:08
一个表,字段比较多,我想从这个表(a)中查出一部分数据插入到另一个表(b)中,但是a表中有时间戳,这样的话,直接
insert into .. select * ..肯定是不行的,但是这个表的字段又比较多,无论是一个一个的写,还是从系统表中把他们查出来都比较麻烦,所以请教各位有没有什么方法能在insert into 里能把时间戳给排除掉,不insert这列?
当然这个问题如果用dts就很简单了,但是我想知道用insert into select 不用把列名全列出来,还能排除指定的列?
...全文
208 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pt1314917 2010-08-21
  • 打赏
  • 举报
回复

declare @sql varchar(500)
select @sql=isnull(@sql+',','insert into b select ')+name from syscolumns
where id=object_id('a') and name<>'时间戳字段'
exec(@sql)
claro 2010-08-21
  • 打赏
  • 举报
回复
...
wyfccc 2010-08-21
  • 打赏
  • 举报
回复
最好不要用*, 危险得累!
nnnewg 2010-08-21
  • 打赏
  • 举报
回复

建立一个不含时间戳的视图 然后:insert into ... select from 视图
duanzhi1984 2010-08-21
  • 打赏
  • 举报
回复
时间戳能否自动生成呢
SQLCenter 2010-08-21
  • 打赏
  • 举报
回复
没有这功能吧
pt1314917 2010-08-21
  • 打赏
  • 举报
回复

--上面写掉了。还差一点:
declare @sql varchar(500)
select @sql=isnull(@sql+',','insert into b select ')+name from syscolumns
where id=object_id('a') and name<>'时间戳字段'
set @sql=@sql+' from a'
exec(@sql)

34,871

社区成员

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

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