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

    WWGD

    User Avatar
    Science Advisor
    Gold Member

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

    jedishrfu

    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:

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Syntax in T-SQL
  1. Sql join? (Replies: 4)

  2. SQL Help (Replies: 2)

Loading...