If you want to update the
SADDRESS
of particular rows then,
WHERE
clause can be used like
UPDATE Student
SET SADDRESS = 'chennai,india' WHERE SID IN (1,2, 10)
GO
here I assumed that
SID
is of type
int
and used
IN
clause. Instead of that any WHERE condition can be used as required.
If
SADDRESS
in all rows is to be set then
UPDATE Student
SET SADDRESS = 'chennai,india'
GO
can be used.
[Edit]The following added to update the rows of table from another table [/Edit]
If address
A
in all rows is to be replaced address
B
,
address
C
with address
D
and like, then a
Temporary table
can be created and populated with the
old address and corresponding new address
.
Then the rows can be updated as shown below
CREATE TABLE NewValues (OldAddress NVARCHAR(25), NewAddress NVARCHAR(25))
INSERT INTO NewValues
VALUES ('chennai,india','mumbai,india'),
('Add1','Address One'),
('Add2', 'Address Two')
SELECT * FROM NewValues
UPDATE Student
SET Student.SADDRESS = NewValues.NewAddress
FROM NewValues
INNER JOIN Student
ON Student.SADDRESS = NewValues.OldAddress
DROP TABLE NewValues
SELECT * FROM Student