Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is scope in SQL Server / how is it defined?

Tags:

sql-server

I am trying to find documentation on SQL Server where concept of scope is defined. I just want to understand it better.

I had been looking at scope_identity() function and it says that @@identity result and scope_identity() result will differ in case there are triggers defined which insert records into another table with an identity column.

It seems scope_identity() decides that insert in the trigger is in different scope. I want to see how that is determined/where it is documented...

like image 888
nee21 Avatar asked Sep 01 '15 20:09

nee21


People also ask

What is the scope of view in SQL?

Views in SQL are kind of virtual tables. A view also has rows and columns as they are in a real table in the database. We can create a view by selecting fields from one or more tables present in the database. A View can either have all the rows of a table or specific rows based on certain condition.

Is there any scope in SQL?

SQL is a massive technology. The future scope of being an SQL Developer it is not just limited to Computer Science, but you can see it revolving around Retail, Finance, Healthcare, Science & Technology, Public Sector, in short everywhere. All organizations need a database for the storage of their data.

What are the 3 types of functions in SQL Server?

There are three types of user-defined functions in SQL Server: Scalar Functions (Returns A Single Value) Inline Table Valued Functions (Contains a single TSQL statement and returns a Table Set) Multi-Statement Table Valued Functions (Contains multiple TSQL statements and returns Table Set)

What is a user-defined function in SQL?

A user-defined function (UDF) lets you create a function by using a SQL expression or JavaScript code. A UDF accepts columns of input, performs actions on the input, and returns the result of those actions as a value. You can define a UDFs as either persistent or temporary.


1 Answers

A scope is a module: a stored procedure, trigger, function, or batch. Therefore, two statements are in the same scope if they are in the same stored procedure, function, or batch.

https://msdn.microsoft.com/en-us/library/ms190315.aspx

like image 119
jmc Avatar answered Oct 01 '22 02:10

jmc