Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Syntax in T-SQL

  1. Apr 21, 2016 #1


    User Avatar
    Science Advisor
    Gold Member

    Hi, I wonder if someone remembers their T-SQL. We have this statement:


    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.
    Last edited: Apr 21, 2016
  2. jcsd
  3. Apr 21, 2016 #2


    Staff: Mentor

    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:


    and more on object-id:


    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.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Threads for Syntax
Python Memorizing syntax/steps vs. looking things up