Question

I'm learning SQL at the moment, and have found some different methods of updating and setting a table.

For this example, I am wondering what is the "most correct way" of doing this?

    UPDATE student
    SET test1 = 7, test2 = 9
    where stuid = 999

or

    UPDATE student
    SET test1 = 7
    where stuid = 999
    UPDATE student
    SET test2 = 9
    where stuid = 999

Thanks.

Was it helpful?

Solution

Firstly always Google yourself before posting any Questions.

The answer (as said by others) is off-course the Method 1. As it will not reload the database Twice.

Also if you are Beginner try to go learn from W3Schools

OTHER TIPS

Running one update statement is always better than two. I choose the first one. It will only run on the database once and updates two columns.

I will go with first statement because its just 1 call to database server.

I suggest the first, don't repeat yourself, and always write neat codes.

Statement 1 is without any doubt better than statement 2 ... Why to load the db server twice than required ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top