Updating the data in a table

  • Question: when inserting data into a table I thought it had to be INSERT INTO table VALUES ... but the question is INSERT T1 Values. I guessed Error because it wouldn't make it to the update. Please let me know if this is a valid way to write an insert statement.

    Thanks.

  • DBA by default (2/28/2013)


    Question: when inserting data into a table I thought it had to be INSERT INTO table VALUES ... but the question is INSERT T1 Values. I guessed Error because it wouldn't make it to the update. Please let me know if this is a valid way to write an insert statement.

    Thanks.

    The INTO keyword is optional.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Thanks I guess you learn something new everyday.

  • Just a bit of mental gymnastics... Thanks, Gary!

  • Good question.... Had to stare at it a while due to lack of sleep and too much food. Glad I figured it out and was able to asnwer it though.



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • Nice Question..

    Thank You.

  • Thanks for the great question! πŸ˜€ I almost pulled the trigger and went 5,6,7,8 but I stopped myself before it was too late.



    Everything is awesome!

  • That was an interesting question and thanks for your contribution. πŸ™‚

  • EZ PZ

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Easy one..

    Remembering the basic methodology of Update.

    I forget the exact term which prevents data getting updated recursively.

    --
    Dineshbabu
    Desire to learn new things..

  • Thanks for the question.

  • Thank you for the quetsion easy one for me.

    β€œWhen I hear somebody sigh, β€˜Life is hard,’ I am always tempted to ask, β€˜Compared to what?’” - Sydney Harris

  • Yes both will have same output . But execuation plan will differ.

  • Good question, but I learned from the question a new option when doing an insert statement. Inserting multiple rows with one SQL statement.

    INSERT T1

    VALUES ( 1 ),

    ( 2 ),

    ( 3 ),

    ( 4 )

    instead of

    INSERT T1 VALUES (1)

    INSERT T1 VALUES (2)

    INSERT T1 VALUES (3)

    INSERT T1 VALUES (4)

    From what I have read, this is new with 2008 and the introduction of "Table Value Constructors".

    http://msdn.microsoft.com/en-us/library/dd776382%28v=sql.105%29.aspx

    This will save me a ton of time. I get lists of data all of the time that I have to insert into a temp table and do queries on. I will no longer have to include the "INSERT INTO..." statement for every row.

    Very Nice,

    Anton

  • Good question. +1

Viewing 15 posts - 16 through 30 (of 31 total)

You must be logged in to reply to this topic. Login to reply