惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - Rickel

在webView 中使用JS 调用 Android / IOS的函数 Function 数据库镜像的配置 查看SQL Server中某数据库下每个表占用的空间大小 about WBS TFS服务器及服务帐号迁域的处理 [西安招聘] 微软西安分公司 招聘.NET软件工程师,MOSS开发工程师 SQL清除数据库日志方法 JavaScript 中的Key 事件区别 ASP.NET URL Rewrite. URL重写 生成高品质的缩略图 Apache Error:(OS 10048)Only one usage of each socket address is normally permitted. 页面响应自定义控件的事件 推荐大家看 《亵渎》 断字处理 break-word I'm Back 部署带Crystal Reports的Web应用程序 - Rickel 用C#读取Excel文件:从指定单元格开始向右向下读取数据 Well-formed AssemblyInfo.cs 毕业一周年纪念
sql server 2005 压缩实例下所有数据库文件及日志文件 语句
Rickel · 2008-10-07 · via 博客园 - Rickel

--01.get all database name
SELECT DBNAME   = DB_NAME(s_mf.database_id)    INTO #DN
    
FROM

        sys.master_files s_mf
    
WHERE
        s_mf.state 
= 0 and -- ONLINE
        HAS_DBACCESS(DB_NAME(s_mf.database_id)) = 1 -- Only look at databases to which we have access
    GROUP BY s_mf.database_id
    
ORDER BY 1

--02.use cursor to fetch db name
--
---02.01 declare cursor
DECLARE cur CURSOR FOR 
SELECT DBNAME FROM
 #DN-----02.02 open cursor & declare var
OPEN cur
DECLARE @DbName VARCHAR(200
)
-----02.03 loop db bane
FETCH NEXT FROM cur into @DbName
WHILE(@@FETCH_STATUS=0)
  
BEGIN

        
print 'shrinking ' + @DbName + ' ...'
-------02.04 only shink log file

        
exec(
            
'

                declare @dn varchar(200);
                declare @ln varchar(210);
                select @dn = name from  
'+@DbName+'.dbo.sysfiles where fileid=1 
                select @ln = name from  
'+@DbName+'
.dbo.sysfiles where fileid=2 
                use [
'+ @DbName + '] backup log ['+ @DbName +'
] with no_log dbcc shrinkfile (@ln)
            
'

            )
-------02.04 shink db file & log file
    --  dbcc SHRINKDATABASE (@DbName)
        print @DbName + ' done'
      
FETCH NEXT FROM cur INTO @DbName
  
END
-----02.05 colse cursor
CLOSE cur
DEALLOCATE
 cur
-----03.drop temp table

DROP TABLE #DN
-------------------------------
测试服务器的sql和日志经常就太大了,写一个存储过程,然后job定期执行,避免磁盘空间浪费