문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top