Updating in sql

Rated 4.97/5 based on 923 customer reviews

Then I created a new table named with schoolnew and similarly executed above actions on it.

Then, to view inserted records in it, I execute SELECT command.

updating in sql-89

updating in sql-67

updating in sql-89

updating in sql-14

Adding a WHERE clause would limit the result set of the JOINed table as well.

Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

If this code answers the question, consider adding adding some text explaining the code in your answer. Or even use table variable like @tbl, "on Perm Table. What I usually do is putting everything in a rollbacked transaction and using the "OUTPUT": in this way I see everything that is about to happen.

This way, you are far more likely to get more upvotes — and help the questioner learn something new.-- Sample data: --------------------------------------------------------------------------- CREATE TABLE #SOURCE ([ID] INT, [Desc] VARCHAR(10)); CREATE TABLE #DESTINATION ([ID] INT, [Desc] VARCHAR(10)) INSERT INTO #SOURCE VALUES(1,'Desc_1'), (2, 'Desc_2'), (3, 'Desc_3'); INSERT INTO #DESTINATION VALUES(1,'Desc_4'), (2, 'Desc_5'), (3, 'Desc_6'); --------------------------------------------------------------------------- UPDATE #DESTINATION SET #DESTINATION.[Desc] = #SOURCE.[Desc] FROM #SOURCE WHERE #DESTINATION.[ID] = #SOURCE.[ID] AND #Source.[Desc] = 'Desc_2' I think if you use [_id] on your #SOURCE not [ID] the same as #DESTINATION's, they might let you do JOIN. When I am happy with what I see, i change the ROLLBACK into COMMIT.

Leave a Reply