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

  • Thread starter Thread starter WWGD
  • Start date Start date
  • Tags Tags
    Set
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 1K views
Messages
7,819
Reaction score
13,151
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:
on Phys.org
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
 
  • Like
Likes   Reactions: WWGD