我正在尝试根据主键在表列表(~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 *)。
是否有一种简单的方法可以选择除类型时间戳之外的所有列,还是我需要进入信息模式并为每个表构建动态选择语句?
(或隐含的问题,有没有更好的方法来做我想做的事情?)
谢谢