SQL Server常用的语句

查看锁表语句:

select request_session_id as spid, object_name(resource_associated_entity_id) as tablename
from sys.dm_tran_locks
where resource_type = 'OBJECT';
查询数据库的所有数据表:
select name from sysobjects where xtype='U'
查看当前数据的事务隔离级别:
DBCC USEROPTIONS;

select session_id,
(case transaction_isolation_level 
when 1 then 'ReadUncomitted'
when 2 then 'ReadCommitted'
when 3 then 'Repeatable'
when 4 then 'Serializable'
when 5 then 'Snapshot' 
end) [transaction_isolation_level]
from sys.dm_exec_sessions where session_id=@@SPID;

查询表名和备注:

select c.name,cast(isnull(f.[value], '') as nvarchar(100)) as remark from sys.objects c  left join sys.extended_properties f on f.major_id=c.object_id and f.minor_id=0 and f.class=1 where c.type='u'
查询字段名,属性和备注:

select a.name,a.system_type_id as type, cast(isnull(e.[value],'') as nvarchar(100)) as remark 
from  sys.columns a inner join sys.objects c on a.object_id=c.object_id and c.type='u' 
left join sys.extended_properties e on e.major_id=c.object_id 
and e.minor_id=a.column_id and e.class=1 where c.name='table_name'




















你可能感兴趣的:(sqlserver,事务隔离级别,锁表语句)