首页 > 代码库 > 遍历数据库全部表,将是datetime类型的列的值进行更新
遍历数据库全部表,将是datetime类型的列的值进行更新
declare @tablename nvarchar(80)
declare @cloumn nvarchar(80)
declare @sql nvarchar(400)
declare c1 cursor scroll for
select table_name,column_name from information_schema.columns where DATA_TYPE=‘datetime‘
open c1
fetch first from c1 into @tablename,@cloumn
while @@fetch_status=0
begin
set @sql=‘update ‘+@tablename+‘ set ‘+@cloumn+‘=DATEADD(yy,10,‘+@cloumn+‘) where ‘+@cloumn+‘ is not null‘;
exec (@sql)
fetch next from c1 into @tablename,@cloumn
end
close c1
declare @cloumn nvarchar(80)
declare @sql nvarchar(400)
declare c1 cursor scroll for
select table_name,column_name from information_schema.columns where DATA_TYPE=‘datetime‘
open c1
fetch first from c1 into @tablename,@cloumn
while @@fetch_status=0
begin
set @sql=‘update ‘+@tablename+‘ set ‘+@cloumn+‘=DATEADD(yy,10,‘+@cloumn+‘) where ‘+@cloumn+‘ is not null‘;
exec (@sql)
fetch next from c1 into @tablename,@cloumn
end
close c1
遍历数据库全部表,将是datetime类型的列的值进行更新
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。