sql server 2008数据库维护都有哪些
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql server 2008数据库维护都有哪些相关的知识,希望对你有一定的参考价值。
参考技术A 一:目标任务:使用SQL
Server
2008自带的维护计划自动备份数据库,并且自动删除超过设定期限的历史备份文件:
1.
每天0点自动备份指定数据库
testDB,备份文件放在E:\autoBack文件夹下
2.
备份文件保留1周,每天备份完数据库后自动删除超过1周的备份文件
二:前提条件
1.
已经安装SQL
Server
Integration
Services
服务
2.
已经安装SQL
Server
代理
(MSSQLSERVER)
服务
如果未安装SQL
Server
Integration
Services
服务,依然可以创建维护计划,但是不会生效
三:
创建维护计划(使用维护计划向导)
1.
选择对象资源管理器下的“管理”,点击右键,选择“维护计划向导”
2.
选择“下一步”进入“选择计划属性”界面,
我们这里修改计划名称为
testMaintenancePlan
因为我们现在有两个任务,一个是备份数据库testDB,一个是删除历史备份文件。所以选择“整个计划统筹安排或无计划”
3.
点击“更改”按钮,进入时间计划设置界面
我们这里需要每天重复执行,频率是每天0点钟执行,从当天开始执行
4.
点击“确定”后,返回计划属性界面
5.
选择“下一步”,进入选择维护任务界面
我们这里有两个任务,备份数据库和删除超期的历史备份文件,所以勾选“备份数据库(完整)”和“‘清除维护’任务”两个任务
6.
选择“下一步”,
进入设置维护任务顺序的界面
这里的顺序是先备份数据库,
再执行“清除维护”任务,删除历史备份
7.
选择“下一步”,进入备份数据库任务的设置界面
选择指定的特定数据库testDB:
指定备份文件存放的目录为E:\autoBack
备份文件扩展名为bak(默认),bak字母前面不要加点(
.
)
8.
选择“下一步”进入“定义清除维护任务”界面
我们需要删除文件夹(E:\autoBack)下面的以bak为扩展名的数据库备份文件,文件保留时间为1周,
这里需要注意的是,
文件扩展名填“bak”而不要填“.bak”,扩展名前不要加点,否则不会删除
9.
选择“下一步”设置报告文件路径
10.
选择“下一步”完成
11.
刷新“管理”
下的“维护计划”文件夹,
可以看到创建的维护计划
12.
双击新建的维护计划或点击右键选择“修改”,可以看到维护计划的内容,并修改,修改后点击保存即可
13.
最后重启SQL
Server
代理
服务即可
???Sql Server???SQL SERVER ????????????
?????????int with ?????? serve span ?????? inner -- blog
??????:???Sql Server???SQL SERVER ??????????????????SQL SERVER 2005?????????????????????????????????????????????SQL SERVER 2005???????????????CTE?????????????????????CTE?????????????????????
??????CTE??????????????????Common Table Expression ???SQL SERVER 2005????????????????????????????????????
#??????????????????
1???sql
1 Create table GroupInfo([Id] int,[GroupName] nvarchar(50),[ParentGroupId] int) 2 3 Insert GroupInfo 4 5 select 0,??????????????????,null union all 6 7 select 1,??????????????????,0 union all 8 select 2,??????????????????,1 union all 9 select 3,??????????????????,1 union all 10 select 4,????????????????????????,2 union all 11 select 5,????????????????????????,2 union all 12 select 6,????????????????????????,3 union all 13 select 7,????????????????????????,3 union all 14 15 select 8, ???????????????,0 union all 16 select 9, ?????????????????????,8 union all 17 select 10,????????????????????????,8 union all 18 select 11,???????????????????????????,9 union all 19 select 12,???????????????????????????,9 union all 20 select 13,??????????????????????????????,10 union all 21 select 14,??????????????????????????????,10
2????????????
#????????????Demo
1???????????????????????????????????????????????????,???????????????????????????
1 --???????????????????????????????????????????????? 2 with 3 CTE 4 as 5 ( 6 select * from GroupInfo where Id=1 7 union all 8 select G.* from CTE inner join GroupInfo as G 9 on CTE.Id=G.ParentGroupId 10 ) 11 select * from CTE order by Id
1 --???????????????????????????????????????????????? 2 with 3 CTE 4 as 5 ( 6 select * from GroupInfo where Id=14 7 union all 8 select G.* from CTE inner join GroupInfo as G 9 on CTE.ParentGroupId=G.Id 10 ) 11 select * from CTE order by Id
2?????????????????????
1 --?????????????????? 2 with 3 CTE 4 as 5 ( 6 select Id,GroupName,ParentGroupId,GroupPath=CAST( GroupName as nvarchar(max)) from GroupInfo where Id=1 7 union all 8 select G.*,CAST(CTE.GroupPath+???//???+G.GroupName as nvarchar(max)) as GroupPath from CTE 9 inner join GroupInfo as G 10 on CTE.Id=G.ParentGroupId 11 ) 12 select * from CTE
3?????????????????????????????????????????????????????????
1 --??????id????????????????????????????????????sort??????????????????sort?????????????????????????????????????????????????????? 2 WITH 3 CTE 4 AS 5 ( 6 SELECT * ,CAST(RIGHT(???000??? + CAST([Id] AS VARCHAR), 3) AS VARCHAR(MAX)) AS sort FROM GroupInfo 7 WHERE ParentGroupId = 0 8 UNION ALL 9 SELECT GroupInfo.* ,CAST(sort + RIGHT(???000??? + CAST(GroupInfo.[Id] AS VARCHAR),3) AS VARCHAR(MAX)) AS sort 10 FROM CTE 11 INNER JOIN GroupInfo ON CTE.Id = GroupInfo.ParentGroupId 12 ) 13 SELECT * FROM CTE ORDER BY sort
4?????????????????????????????????????????????????????????
1 --?????????????????? 2 WITH CTE AS ( 3 SELECT *,1 AS [Level] FROM GroupInfo WHERE ParentGroupId=0 4 UNION ALL 5 SELECT G.*,CTE.Level+1 FROM GroupInfo as G 6 JOIN CTE ON CTE.Id =G.ParentGroupId 7 ) 8 SELECT * FROM CTE
以上是关于sql server 2008数据库维护都有哪些的主要内容,如果未能解决你的问题,请参考以下文章