数据库专题有三:设计、执行及优化、管理;本处为一些零散管理片断,有点杂,先归类到此。
#清除SQL Management Studio记住的用户名和密码
SQL Server Management Studio 2008 delete the file C:\Users\%username%\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin
SQL Server Management Studio 2005 delete the file – same as above answer but the Vista path.C:\Users\%username%\AppData\Roaming \Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat
The Profile path for Windows 2003 or Xp is
C:\Documents and Settings\Administrator\Application Data\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM
If you can not find the path,you can use a tool to find the file which file name is mru.dat
At the end ,the all recold will clear as soon as you delete mru.dat
##SQL2008:如何解决“阻止保存要求重新创建表的更改”
当用户在在SQL Server 2008企业管理器中更改表结构时,必须要先删除原来的表,然后重新创建新表,才能完成表的更改,如果强行更改会出现以下提示:不允许保存更改。您所做的更改要求删除并重新创建以下表。您对无法重新创建的标进行了更改或者启用了“阻止保存要求重新创建表的更改”选项。如果要去掉此提示,可从“工具”菜单中选择“选项”,在“选项”对话框中,选择Designers,选择“表设计器和数据库设计器”,清除“ 阻止保存要求重新创建表的更改”复选框。
##创建快照
数据库服务器上先新建文件夹 D:\SqlKuaiZhao\Data\
CREATE DATABASE [myDBKZ] ON
( NAME = N'myDBIssued',
FILENAME = N'D:\SqlKuaiZhao\Data\myDBKZ.ss'
) AS SNAPSHOT OF [myDB]
GO
## 杀死正在使用数据库的线程以获得独占访问权(当还原无法获得对数据库的独占访问权时可以执行此操作)
use master
declare @dbname varchar( 20)
set @dbname='tttt'
declare @sql nvarchar( 500)
declare @spid int--SPID 值是当用户进行连接时指派给该连接的一个唯一的整数
set @sql='declare getspid cursor for
select spid from sysprocesses where dbid=db_id('''+@dbname+''')'
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status<>-1-- 如果FETCH 语句没有执行失败或此行不在结果集中。
begin
exec('kill '+@spid)--终止正常连接
fetch next from getspid into @spid
end
close getspid
deallocate getspid
--另外,也可以直接右击数据库服务器,选择“活动和监视器”,查看使用此数据库的进程,右击选中停止进程即可。