# SqlServer 常用查询语句

SELECT request_session_id AS spid, OBJECT_NAME(resource_associated_entity_id) AS tableName
FROM sys.dm_tran_locks
WHERE resource_type = 'OBJECT'
    AND OBJECT_NAME(resource_associated_entity_id) IS NOT NULL;
1
2
3
4
SELECT 'kill ' + CAST(request_session_id AS VARCHAR(20)) AS spid
FROM sys.dm_tran_locks
WHERE resource_type = 'OBJECT'
    AND OBJECT_NAME(resource_associated_entity_id) IS NOT NULL;
1
2
3
4
select * from table order by Id offset 0 rows fetch next 10 rows only;
1
SELECT COUNT(1) FROM TableName WHERE 1 = 1;

SELECT *
FROM (
    SELECT ROW_NUMBER() OVER (ORDER BY Id DESC) AS RowId, *
    FROM TableName
    WHERE 1 = 1
) t
WHERE t.RowId BETWEEN @page AND @limit;
1
2
3
4
5
6
7
8
9