1、压缩数据库
dbcc shrinkdatabase(dbname)
2、转移数据库给新用户已存在用户权限
exec sp_change_users_login'update_one','newgame','oldname'
go
3、检查备份集
RESTORE VERIFYONLY from disk='E\dvbbs.bak'
4、修复数据库
ALTER DATABASE [dvbbs] SET SINGLE_USER
GO
DBCC CHECKDB('dvbbs',repair_allow_data_loss)with tablelock
go
alter database[dvbbs] set multi_user
go
5、SQL SERVER写入循环
declare @i int
set @i=1
while @i<30
begin
insert into test(userid) values(@i)
set @i=@i+1
end
6、杀掉所有的事件探查器进程
DECLARE hcforeach CURSOR GLOBAL FOR SELECT 'kii' + RTRIM(spid) from master.dbo.sysprocesses where program_name in('SQL profiler',N'SQL事件探查器')
exec sp_msforecach_worker'?'
7、查看与某一个表相关的视图、存储过程、函数
select a.* from sysobjects a,syscomments b where a.id=b.id and b.text
like'%表名%'
8、查看当前数据库中所有存储过程
select name as 存储过程名称 from sysobjects where xtype='P'
9、查看主键列
select * from sysobjects where xtype='PK'
10、重建索引
ALTER INDEX Idx_name ON tblCompany REBUILD