How to Update table data in SQL Server using command?

Asked 14-Sep-2021
Viewed 565 times

1 Answer


0

SQL UPDATE Statement –
The ‘update’ statement is used to modified the existing record in a table. In this case notice the WHERE clause. Data are modified where the WHERE clause fulfill the condition. If we don’t provide WHERE clause in UPDATE statement then all data will changed.
Syntax-
 UPDATE tablename SET column1=value1, column2=value2,…. WHERE condition;
Bellow the example of UPDATE statement in a table. Record of the table are as-
                            How to Update table data in SQL Server using command?
Following statement is UPDATE the stuCourse ‘Marketing’ to ‘Marketing Course’ of ‘StudentData’ table where Id is 103.
update StudentData set stuCourse ='Marketing Course' where Id=103;
                            How to Update table data in SQL Server using command?

 UPDATE multiple record of ‘StudentData’ table. We can also assign value in that field which contain NULL value.
Following statement modified the ‘stuName’ and ‘stuCourse’ of ‘StudentData’ table where Id=104.
update StudentData set stuName='Sundar', stuCourse='B.Tech' where Id=104;
                     How to Update table data in SQL Server using command?
If you forget the use WHERE clause in UPDATE statement then you find the result like as-
update StudentData set stuCourse='Software Trainee';
                    How to Update table data in SQL Server using command?