【发布时间】:2015-03-25 05:36:43
【问题描述】:
我正在尝试根据主键剔除表列表 (~30) 中的数据。
我的方法是:
1.创建一个中间表并为每个表加载所需的数据
2.截断原表
3.将中间表中的数据插回原表中。
这是我目前使用的代码:
declare @table nvarchar(max)
open tab
fetch next from tab into @table
while(@@FETCH_STATUS = 0)
begin
print @table
exec ('select * into ' +@table+'_intermediate from '+@table+' where P_ID in( select P_ID from pc_table )')
exec ('truncate table '+@table)
exec ('insert into '+@table+' select * from '+@table+'_intermediate')
exec ('drop table '+@table+'_intermediate')
fetch next from tab into @table
end
close tab
deallocate tab
我遇到了一个错误:
Cannot insert an explicit value into a timestamp column.
Use INSERT with a column list to exclude the timestamp column,
or insert a DEFAULT into the timestamp column.
所以,该错误告诉我无法在时间戳列中插入任何内容。
为了避免选择时间戳,我需要避免选择它(即使用 select *)。
是否有一种简单的方法来选择除类型时间戳之外的所有列,还是我需要进入信息架构并为每个表构建一个动态选择语句?
(或隐含的问题,有没有更好的方法来做我想做的事情?)
谢谢
【问题讨论】:
标签: sql-server-2008 dml sql-timestamp