sql查询锁

查询锁表
select   request_session_id   spid,OBJECT_NAME(resource_associated_entity_id) tableName   
from   sys.dm_tran_locks where resource_type='OBJECT'
解锁
--declare @spid  int
--Set @spid  = 60
--declare @sql varchar(1000)
--set @sql='kill '+cast(@spid  as varchar)
--exec(@sql)

递归查出所有的下级
with cte (usercode,parentcode,username)
as (
select usercode,parentcode,username from useragent where parentcode='DL000320'
union all
select t.usercode,t.parentcode,t.username from useragent as t inner join cte as c on t.parentcode=c.usercode
)
数组弄成字符串
string.Join(",", proidA.Select(p => "'" + p + "'"))

连表查询修改
update lsf_user set parentname=T_Invite.name from T_Invite where lsf_user.[user]=T_Invite.BelondId

清除日志
ALTER DATABASE 表
SET RECOVERY SIMPLE WITH NO_WAIT
ALTER DATABASE 表
SET RECOVERY SIMPLE
GO
DECLARE @logname VARCHAR(150)
SELECT @logname = NAME
FROM sys.database_files
WHERE NAME LIKE'%log'
DBCC SHRINKFILE(@logname, 11, TRUNCATEONLY)
GO
USE [master]
ALTER DATABASE 表
SET RECOVERY FULL WITH NO_WAIT
ALTER DATABASE 表
SET RECOVERY FULL
GO

 

-- 1.添加PRIMARY KEY(主键索引)
ALTER TABLE `table_name` ADD PRIMARY KEY (`column`) ;
-- 2.添加UNIQUE(唯一索引)
ALTER TABLE `table_name` ADD UNIQUE (`column`);
-- 3.添加INDEX(普通索引)
ALTER TABLE `table_name` ADD INDEX index_name (`column`);
-- 4.添加FULLTEXT(全文索引)
ALTER TABLE `table_name` ADD FULLTEXT (`column`);
-- 5.添加多列索引
ALTER TABLE `table_name` ADD INDEX index_name (`column1`, `column2`, `column3`);

你可能感兴趣的:(sql查询锁)