How to write UPDATE SQL with Table alias in SQL Server 2008?

后端 未结 2 1439
青春惊慌失措
青春惊慌失措 2020-11-28 20:19

I have a very basic UPDATE SQL -

UPDATE HOLD_TABLE Q SET Q.TITLE = \'TEST\' WHERE Q.ID = 101;

This query runs fine in Or

相关标签:
2条回答
  • 2020-11-28 20:42

    The syntax for using an alias in an update statement on SQL Server is as follows:

    UPDATE Q
    SET Q.TITLE = 'TEST'
    FROM HOLD_TABLE Q
    WHERE Q.ID = 101;
    

    The alias should not be necessary here though.

    0 讨论(0)
  • 2020-11-28 20:43

    You can always take the CTE, (Common Tabular Expression), approach.

    ;WITH updateCTE AS
    (
        SELECT ID, TITLE 
        FROM HOLD_TABLE
        WHERE ID = 101
    )
    
    UPDATE updateCTE
    SET TITLE = 'TEST';
    
    0 讨论(0)
提交回复
热议问题