遍历数据库全部表,将是datetime类型的列的值进行更新

Posted slgkaifa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了遍历数据库全部表,将是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 [email protected]+‘ set  [email protected]+‘=DATEADD(yy,10,‘[email protected]+‘)  where [email protected]+‘ is not null‘;
      exec (@sql)
     fetch next from c1 into @tablename,@cloumn
   end
close c1

以上是关于遍历数据库全部表,将是datetime类型的列的值进行更新的主要内容,如果未能解决你的问题,请参考以下文章