刪除SQL Server日志的方法(4)_Mssql數(shù)據(jù)庫(kù)教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
推薦:解讀SQL存儲(chǔ)過程入門級(jí)教程1.SQL存儲(chǔ)過程概述 在大型數(shù)據(jù)庫(kù)系統(tǒng)中,存儲(chǔ)過程和觸發(fā)器具有很重要的作用。無(wú)論是存儲(chǔ)過程還是觸發(fā)器,都是SQL語(yǔ)句和流程控制語(yǔ)句的集合。就本質(zhì)而言,觸發(fā)器也是一種存儲(chǔ)過程。存儲(chǔ)過程在運(yùn)算時(shí)生成執(zhí)行方式,所以,以后對(duì)其再運(yùn)行時(shí)其執(zhí)行速度很快。SQLSe
--5.分離數(shù)據(jù)庫(kù)
if @bkdatabase=1
begin
if isnull(@bkfname,’’)=’’
set @bkfname=@dbname+’_’+convert(varchar,getdate(),112)
+replace(convert(varchar,getdate(),108),’:’,’’)
select 提示信息=’備份數(shù)據(jù)庫(kù)到SQL 默認(rèn)備份目錄,備份文件名:’+@bkfname
exec(’backup database [’+@dbname+’] to disk=’’’+@bkfname+’’’’)
end
--進(jìn)行分離處理
create table #t(fname nvarchar(260),type int)
exec(’insert into #t select filename,type=status&0x40 from [’+@dbname+’]..sysfiles’)
exec(’sp_detach_db ’’’+@dbname+’’’’)
--刪除日志文件
declare @fname nvarchar(260),@s varchar(8000)
declare tb cursor local for select fname from #t where type=64
open tb
fetch next from tb into @fname
while @@fetch_status=0
begin
set @s=’del "’+rtrim(@fname)+’"’
exec master..xp_cmdshell @s,no_output
fetch next from tb into @fname
end
close tb
deallocate tb
--附加數(shù)據(jù)庫(kù)
set @s=’’
declare tb cursor local for select fname from #t where type=0
open tb
fetch next from tb into @fname
while @@fetch_status=0
begin
set @s=@s+’,’’’+rtrim(@fname)+’’’’
fetch next from tb into @fname
end
close tb
deallocate tb
exec(’sp_attach_single_file_db ’’’+@dbname+’’’’+@s)
go
分享:按指定排列順序獲取數(shù)據(jù)的sql語(yǔ)句測(cè)試table create table table1 (id int,name char) insert into table1 select 1,'q' union all select 2,'r' union all select 3,'3' union all select 4,'5' 要求按指定的id順序(比如2,1,4,3)排列獲取table1的數(shù)據(jù) 方法1: 使用union all,但是有256條數(shù)據(jù)的
相關(guān)Mssql數(shù)據(jù)庫(kù)教程:
- sql 語(yǔ)句練習(xí)與答案
- 深入C++ string.find()函數(shù)的用法總結(jié)
- SQL Server中刪除重復(fù)數(shù)據(jù)的幾個(gè)方法
- sql刪除重復(fù)數(shù)據(jù)的詳細(xì)方法
- SQL SERVER 2000安裝教程圖文詳解
- 使用sql server management studio 2008 無(wú)法查看數(shù)據(jù)庫(kù),提示 無(wú)法為該請(qǐng)求檢索數(shù)據(jù) 錯(cuò)誤916解決方法
- SQLServer日志清空語(yǔ)句(sql2000,sql2005,sql2008)
- Sql Server 2008完全卸載方法(其他版本類似)
- sql server 2008 不允許保存更改,您所做的更改要求刪除并重新創(chuàng)建以下表
- SQL Server 2008 清空刪除日志文件(瞬間日志變幾M)
- Win7系統(tǒng)安裝MySQL5.5.21圖解教程
- 將DataTable作為存儲(chǔ)過程參數(shù)的用法實(shí)例詳解
Mssql數(shù)據(jù)庫(kù)教程Rss訂閱編程教程搜索
Mssql數(shù)據(jù)庫(kù)教程推薦
- 揭秘操作日期的SQL語(yǔ)句大全
- 使用SQL Server 2000日志轉(zhuǎn)移實(shí)現(xiàn)高可用性
- 如何查看并導(dǎo)出數(shù)據(jù)表中字段的注釋信息
- SQL Server 索引基礎(chǔ)知識(shí)(2)----聚集索引,非聚集索引
- 基于B-樹和B+樹的使用:數(shù)據(jù)搜索和數(shù)據(jù)庫(kù)索引的詳細(xì)介紹
- SQL Server 2005基于消息的應(yīng)用程序介紹
- 循序漸進(jìn)講解數(shù)據(jù)表的十二個(gè)設(shè)計(jì)原則
- 讓SQL Server數(shù)據(jù)庫(kù)自動(dòng)執(zhí)行管理任務(wù)(二)
- Sql Server 2008完全卸載方法(其他版本類似)
- 如何查看SQL執(zhí)行計(jì)劃
- 相關(guān)鏈接:
- 教程說明:
Mssql數(shù)據(jù)庫(kù)教程-刪除SQL Server日志的方法(4)
。