DECLARE @sqlString NVARCHAR(max)
DECLARE @union NVARCHAR(max)
SET @sqlString = ''
SET @union = ''
DECLARE @name nvarchar(50);
DECLARE crs CURSOR FOR
SELECT Name FROM sys.databases WHERE state = 0
OPEN crs
FETCH NEXT FROM crs INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sqlString = @sqlString + @union
SET @sqlString = @sqlString + '
SELECT
TOP 1
''' + @name + ''' as DBName, modify_date
FROM
[' + @name + '].sys.tables'
SET @union = ' UNION '
FETCH NEXT FROM crs INTO @name
END
SET @sqlString = @sqlString + ' ORDER BY DBName ASC'
CLOSE crs;
DEALLOCATE crs;
EXEC(@sqlString)
DECLARE @union NVARCHAR(max)
SET @sqlString = ''
SET @union = ''
DECLARE @name nvarchar(50);
DECLARE crs CURSOR FOR
SELECT Name FROM sys.databases WHERE state = 0
OPEN crs
FETCH NEXT FROM crs INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sqlString = @sqlString + @union
SET @sqlString = @sqlString + '
SELECT
TOP 1
''' + @name + ''' as DBName, modify_date
FROM
[' + @name + '].sys.tables'
SET @union = ' UNION '
FETCH NEXT FROM crs INTO @name
END
SET @sqlString = @sqlString + ' ORDER BY DBName ASC'
CLOSE crs;
DEALLOCATE crs;
EXEC(@sqlString)
No comments:
Post a Comment