Remembering T-SQL: SET vs SELECT and OBJECT_ID()

  • Thread starter WWGD
  • Start date
  • Tags
    Set
  • #1

WWGD

Science Advisor
Gold Member
6,368
8,698
Hi, I wonder if someone remembers their T-SQL. We have this statement:

upload_2016-4-21_1-52-0.png


Just curious: I remember using SET where SELECT appears. Is this SELECT used in order to
assign values to many variables simultaneously? Also, Is there a reason to use two separate
DECLARE statements , or could we just use a single one?

EDIT : I am also confused about the OBJECT_ID function. I tried it on my SQL Server and got an error message when entering the name of the database I was using, i.e., OBJECT_ID( 'Database Name') generated an error message.
Thanks.
 
Last edited:

Answers and Replies

  • #2
From the examples I saw online it seems object-id is used to determine if tables exist not databases so it probably is used to query database metadata like table names, column names and schema names:

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

and more on object-id:

http://stackoverflow.com/questions/9372867/what-does-object-id-do-in-sql-server

I think the select is just returning a set of values matching the SELECT criteria. I don't think its making some sort of array of values assigned to the variables mentioned. In standard SQL, you'd use an UPDATE or INSERT with an embedded SELECT to pick rows and columns to be inserted/updated in a separate table.

http://www.w3schools.com/sql/sql_insert_into_select.asp
 

Suggested for: Remembering T-SQL: SET vs SELECT and OBJECT_ID()

Replies
1
Views
821
Replies
3
Views
308
Replies
6
Views
321
2
Replies
51
Views
3K
Replies
49
Views
1K
Replies
1
Views
445
Replies
11
Views
2K
Back
Top