随笔分类 - SQL
数据库相关
摘要:--查看所有锁表SELECT request_session_id spid, OBJECT_NAME(resource_associated_entity_id) tableNameFROM sys.dm_tran_locksWHERE resource_type = 'OBJECT' ORDER
阅读全文
摘要:可以使用 FOR XML PATH语法 参考:https://www.cnblogs.com/yasuo2/p/6433697.html
阅读全文
摘要:select distinct id,name ,count(1) from user1 group by id,name
阅读全文
摘要:-- with 一个临时表(括号里包括的是你要查询的列名) with tem_table(dept_id,parent_id,dep_name,curlevel) as ( --1,初始查询(这里的parent_id='000'是我门数据中最底层的根节点) select dept_id, paren
阅读全文
摘要:begin tran at01 begin try 业务逻辑语句 commit tran at01 end try begin catchrollback tran at01INSERT INTO t_log (ErrorMessage,ErrorSeverity,ErrorState,operat
阅读全文
摘要:update a set a.UserRoleName=b.Name from Users a inner join Role b on a.RoleId=b.Id
阅读全文
摘要:SELECT 表名 = Case When A.colorder=1 Then D.name Else '' End, --表说明 = Case When A.colorder=1 Then isnull(F.value,'') Else '' End, 字段序号 = A.colorder, 字段名
阅读全文
摘要:mongodb 的查询语法类似js: var userCods = db.getCollection('items').aggregate([ {$match:{"userItem.userCode":"ACB"}}, {$project:{"userCode":1,"_id":0}} ]) use
阅读全文
摘要:索引 常用存储结构 :b tree 非聚集索引和聚集索引的区别在于, 通过聚集索引可以查到需要查找的数据, 而通过非聚集索引可以查到记录对应的主键值 , 再使用主键的值通过聚集索引查找到需要的数据。 非主流索引(复合、多字段)最终不用聚集索引
阅读全文