Updating the data in a table

  • DBA by default

    SSC-Addicted

    Points: 492

    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.

  • Hugo Kornelis

    SSC Guru

    Points: 64645

    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/

  • DBA by default

    SSC-Addicted

    Points: 492

    Thanks I guess you learn something new everyday.

  • Revenant

    SSC-Forever

    Points: 42467

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

  • mtassin

    SSC-Insane

    Points: 23096

    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]

  • PChiragS

    SSCarpal Tunnel

    Points: 4965

    Nice Question..

    Thank You.

  • Dana Medley

    SSCertifiable

    Points: 6764

    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!

  • zymos

    SSCommitted

    Points: 1960

    That was an interesting question and thanks for your contribution. 🙂

  • SQLRNNR

    SSC Guru

    Points: 281210

    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

  • Dineshbabu

    Hall of Fame

    Points: 3220

    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..

  • (Bob Brown)

    SSCrazy

    Points: 2705

    Thanks for the question.

  • kapfundestanley

    SSCertifiable

    Points: 5627

    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

  • amit_adarsh

    Ten Centuries

    Points: 1273

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

  • aochss

    SSCommitted

    Points: 1677

    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

  • sqlnaive

    SSCoach

    Points: 17435

    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