你可以向我解释这个SQL语句吗? [英] Could you please explain this SQL statement to me?

查看:116
本文介绍了你可以向我解释这个SQL语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想详细了解这个SQL代码及其工作原理吗?



Please I want to understand this SQL code in detail, and how it works?

CREATE PROC AddEmp(@mgrid int, @empid int, @e_name varchar(20), @title varchar(20)) 
AS 
BEGIN
   DECLARE @mOrgNode hierarchyid, @lc hierarchyid
   SELECT @mOrgNode = OrgNode 
   FROM HumanResources.EmployeeOrg 
   WHERE EmployeeID = @mgrid
   SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
   BEGIN TRANSACTION
      SELECT @lc = max(OrgNode) 
      FROM HumanResources.EmployeeOrg 
      WHERE OrgNode.GetAncestor(1) =@mOrgNode ;

      INSERT HumanResources.EmployeeOrg (OrgNode, EmployeeID, EmpName, Title)
      VALUES(@mOrgNode.GetDescendant(@lc, NULL), @empid, @e_name, @title)
   COMMIT
END ;
GO



DECLARE关键字的含义是什么,以及在符号(@),

我知道它与程序的参数有关但在这段代码中我不清楚。



这个例子来自这里的例子:

https:// msdn。 microsoft.com/en-us/library/2c95fa60-5b8e-4a05-ac09-cffe2b05900a(v=sql.110) [ ^ ]

推荐答案

带有@符号的DECLARE声明一个变量。



另外,也许你留下了很多东西,因为这段代码启动了一个事务,但后来只做了一件事在其中,这是浪费交易。



总的来说,它只是选择一些值并在EmployeeOrg表中创建一条记录。
DECLARE with the @ sign is declaring a variable.

Also, perhaps you left a lot out because this code starts a transaction but then only does one thing in it, which is a waste of transaction.

Overall, it just selects some values and creates a record in the EmployeeOrg table.


这篇关于你可以向我解释这个SQL语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆