With the Update Statement, we can update records in a table in the database. The most important thing to note when running this command is to specify the Where condition correctly. If we run the Update command without specifying the condition, all the records in the table are updated.
First, we are creating a table and inserting some data into it for using in our test:
1 2 3 4 5 6 | Use [TestDB] GO CREATE TABLE [dbo].[MyTable] (Name VARCHAR(25)) GO INSERT INTO [dbo].[MyTable] VALUES ('Nurullah CAKIR'),('Faruk ERDEM') |
Then, we update records whose value is ‘Faruk Erdem’ in the name column with the help of the script below:
1 2 3 4 5 6 7 8 9 | USE [TestDB] GO SELECT * FROM [TestDB].[dbo].[MyTable] GO UPDATE [dbo].[MyTable] SET [Name] = 'ERDEM' WHERE [Name]='Faruk Erdem' GO SELECT * FROM [TestDB].[dbo].[MyTable] |