创建包含每个表的 table_name 和 max_date 的表

问题描述

我有一个只有一列 -Table_Name 的表,其中包含数据库中的所有表名。

如何创建一个进程,该进程将使用上表中的所有名称 (Table_Name) 以及每个表的最大更新日期 (Max_Update_Date) 的第二列创建另一个表?

**需要从表本身的 Update_Date 列中取出值

这是我目前得到的 -

DROP TABLE IF EXISTS #TempTable
select  row_number()over (order by a.Table_Name) as rn,a.Table_Name,s.modify_date 
into #TempMasterTable
from API_Tables a left join sys.tables s
on s.name=a.Table_Name

select * from #TempTable

declare @counter int,@table nvarchar(50);

set @counter=(select top 1 rn from #TempTable order by rn desc)

while @counter>0
begin
    set @table=( select table_name
    from #TempTable
    where @counter=rn);

    update #TempTable
    set modify_date=(select max([update_date]) from @table)

    set @counter=@counter-1;

end

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)