MERGE statement

  • Hi guys,

    I have a doubt like can i use merge statement for single table insertion and deletion and updation? Moreover the rows which i specified in condition needs to be updated or deleted or inserted.

    I have StudentDetails which contains 5 rows.The follwoing is the table structure.

    CREATE TABLE StudentDetails

    (

    StudentID INTEGER PRIMARY KEY

    ,StudentName VARCHAR(15)

    ,mark1 decimal(5,2)

    ,mark2 decimal(5,2)

    ,mark3 decimal(5,2)

    )

    can i insert 6 and 7th row and delete the 3 row. and i need to update 2 and 4th row. Is it possible in the single table. please help me out on this.

  • Based on the structure and the statement, this sounds like homework. What have you tried so far that hasn't worked?

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • The MERGE statement is used to merge two tables together so that the destination looks like the source.

    Are these inserts, updates and deletes coming from a different table? If not, where's the info coming from that sayds which to insert, which to update and to what, and which to delete?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 3 posts - 1 through 3 (of 3 total)

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