All Type Coding

Search Here

How to Update Record/Data in a table in sql server.?


Update Command:
                                  The UPDATE command is used to update/modify the existing records in a table.UPDATE  command should be execute  using WHERE clause so that record should be updated selected rows otherwise all the rows would be affected.
syntax of Update statement:
                         UPDATE Table_Name
                         SET Column1=value1,Column2=value2,...
                         WHERE Column_Name=value;



Step1-> Create a table. 


CREATE TABLE [dbo].[Employee](
 [Sno] [int] NULL,
 [Name] [varchar](50) NULL,
 [Address] [varchar](60) NULL,
 [Mobile_No] [varchar](10) NULL


Step2-> Insert data into table.

Insert into Employee
values(1,'AAA','Delhi','8147280584')
Insert into Employee 
values(1,'BBB','Moradabad','9999999999')
Insert into Employee 
values(1,'CCC','Bangalore','8147280584')
Insert into Employee 
values(1,'DDD','Noida','8147280584')
Insert into Employee
values(1,'EEE','Haridwar','9927153056')

Step3-> Write update Query.

 Update Employee 
 set Sno=2,
 Name='ABC',
 Address='Hasanpur'
 where Mobile_No='9447280584'
When will you Execute the above query one row will be affected like below

image






















After executing the above query again execute the select command then output will be like below image. In above query we updated Sno=2,Name=ABC and Address=Hasanpur at the place of Sno=1,Name=CCCand Address=Bangalore based on mobile number. now in below image data updated.



















Here I explained How to update data into database table in sql server.

No comments :

Post a Comment