漂泊雪狼的博客

思考,讨论,分享C#,JavaScript,.NET,Oracle,SQL Server……技术

导航

查看sql server数据库文件信息

Posted on 2016-06-12 11:24  漂泊雪狼  阅读(602)  评论(0编辑  收藏  举报
--drop table #dbfiles
--deallocate cursor1
 
------
declare cursor1 cursor for
    SELECT name from sys.databases
    where state=0
 
-- 临时表  www.2cto.com  
CREATE TABLE #dbfiles
( 
dbname nvarchar(100),
filetype nvarchar(100),
filename nvarchar(200)
)
 
declare @name  varchar(100) --数据库名
declare @sql nvarchar(1024) --临时sql 语句
 
open cursor1
 
fetch next from cursor1 into @name
 
while @@fetch_status = 0
begin  
    set @sql = 'INSERT INTO #dbfiles SELECT ''' + @name + ''',name,filename  from ' + @name + '.sys.sysfiles';
    EXEC(@sql)
 
    fetch next from cursor1 into @name 
end
 
close cursor1                   --关闭游标
deallocate cursor1
 
select * from #dbfiles
--where filename like '%ftysdatabase%'
 
 --F:\ftysdatabase\ty_video.mdf
drop table #dbfiles --删除临时文件