1.查看数据库日志使用率
DBCC SQLPERF(LOGSPACE)
2.查看表结构
sp_help tablename
sp_columns tablename
3.查询中添加行号
select ROW_NUMBER() over (order by main_id), main_id from MC_MF_JXYDJY
4.查询一个数据库中某个字段的位置
declare @cloumns varchar(40) declare @tablename varchar(40) declare @str varchar(40) declare @counts int declare @sql nvarchar(2000) declare MyCursor Cursor For Select a.name as Columns, b.name as TableName from syscolumns a,sysobjects b,systypes c where a.id = b.id and b.type = 'U' and a.xtype=c.xtype and c.name like '%char%' set @str='张三' Open MyCursor Fetch next From MyCursor Into @cloumns,@tablename While(@@Fetch_Status = 0) Begin set @sql='select @tmp_counts=count(*) from ' +@tablename+ ' where ' +@cloumns+' = ''' +@str+ '''' execute sp_executesql @sql,N'@tmp_counts int out',@counts out if @counts>0 begin print '表名为:'+@tablename+',字段名为'+@cloumns end Fetch next From MyCursor Into @cloumns,@tablename End Close MyCursor Deallocate MyCursor
5.查询一个最近的执行语句
SELECT * FROM sys.dm_exec_query_stats QS CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) ST