问题描述:只是单纯的执行了"select count(*) from 某表":数据表中只有一两条数据,能查询其他表,唯独这个表不能进行任何操作: 经百度搜索实验,发现应该是某个进程阻塞了,使用了一下代码进行的查询(这个比较详细): declare @spid int,@bl int ,blocked ) a ) b where a.blocked=spid) union )) + ' 进程号, 其执行的SQL 语法如下' else )))) +' 阻塞, 其当前进程执行的SQL 语法如
查询表名为tb_menu的所有列名 select name from syscolumns where id=object_id('tb_menu') 查询表名为tb_menu的所有列名个数 select count(name) from syscolumns where id=object_id('tb_menu') 或者 select count(syscolumns.name) from syscolumns ,sysobjects where syscolum
create or alter proc SP_CreateIndex as begin if exists(select * from sys.objects where name='execsql') begin drop table execsql; end create table execsql(id int identity(1,1),sqlstr varchar(1000),flag varchar(255));--创建索引insert into execsql(sqlstr,fl
查看系统中最近执行的语句 ST.text AS '执行的SQL语句', QS.execution_count AS '执行次数', QS.total_elapsed_time AS '耗时', QS.total_logical_reads AS '逻辑读取次数', QS.total_logical_writes AS '逻辑写入次数', QS.total_physical_reads AS '物理读取次数', QS.creation_time AS '执行时间' , QS.* FROM sys.
SQL 查询表中31到40的记录,考虑id不连续的情况 写出一条sql语句输出users表中31到40记录(数据库为SQL Server,以自动增长的ID作为主键,注意ID可能不是连续的)? --使用not in select top 10 * from users where id not in(select top 30 id from users order by id asc) order by id asc --使用order by select * from (select to
一.存储过程 1.新增操作存储过程 --------------1.新建 增加学生的存储过程---------------------------- set IDENTITY_INSERT student on go create procedure addStu(@maxcount BIGINT) as begin DECLARE @count int; ; while(@count<@maxcount) begin ) begin +@count,GETDATE(),GETDATE());
SELECT 索引名称=a.name ,表名=c.name ,索引字段名=d.name ,索引字段位置=d.colid ? 1 2 3 4 5 6 7 8 FROM sysindexes a JOIN sysindexkeys b ON a.id=b.id AND a.indid=b.indid JOIN sysobjects c ON b.id=c.id JOIN syscolumns d ON b.id=d.id AND b.colid=d.colid
SELECT [session_id], [request_id], [cpu_time], [start_time] AS '开始时间', [status] AS '状态', [command] AS '命令', dest.[text] AS 'sql语句', [reads] AS '物理读次数', [writes] AS '写次数', [logical_reads] AS '逻辑读次数', [row_count] AS '返回结果行数', [blocking_s
----查询所有的表 SELECT * FROM SYSOBJECTS WHERE TYPE='U' ----根据表名查询所有的字段名及其注释 SELECT A.NAME,B.VALUE FROM SYSCOLUMNS A LEFT JOIN SYS.EXTENDED_PROPERTIES B ON A.ID=B.MAJOR_ID AND A.COLID=B.MINOR_ID INNER JOIN SYSOBJECTS C ON A.ID=C.ID AND UPPER(C.NAME)='tb_n
1.获取主键信息 EXEC sp_pkeys @table_name='{0}' 2.获取外键 方法二 SELECT Field=(SELECT name FROM syscolumns WHERE colid=b.fkey AND id=b.fkeyid) , FKTable=object_name(b.rkeyid), FKKeyField=(SELECT name FROM syscolumns WHERE colid=b.rkey AND id=b.rkeyid) FROM sysobj
SELECT [Table Name] = OBJECT_NAME(c.object_id), [Column Name] = c.name, [Description] = ex.value FROM sys.columns c LEFT OUTER JOIN sys.extended_properties ex ON ex.major_id = c.object_id AND ex.minor_id = c.column_id AND ex.name = 'MS_Description' W