Update column value in Database Table in SQL Server

kankon
 
on Dec 06, 2022 10:33 PM
362 Views

hello

I am trying update multi users if they usa change to kuwait

id        name        city

1         user1       india

2         user2       india

3         user3       kuwait

4         user4       kuwait

5                         kuwait

6                          kuwait

7                          usa

8                          usa

9                          usa

10                        usa

select * from table_infoname
update table_infoname set country=kuwait where id in (1,2)

I know only this.

How to update multiple records, i have like 1000 users of 6000.

I want to change them.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
PrinceG
 
on Dec 06, 2022 11:40 PM

Hi kankon,

Please refer below SQL query.

SQL

CREATE TABLE #Users
(
	[Id] INT PRIMARY KEY,
 	[Name] VARCHAR (20),
	[City] VARCHAR(30)
)
INSERT INTO #Users VALUES (1,'User1','India')
INSERT INTO #Users VALUES (2,'User2','India')
INSERT INTO #Users VALUES (3,'User3','Kuwait')
INSERT INTO #Users VALUES (4,'User4','Kuwait')
INSERT INTO #Users VALUES (5,'User5','Kuwait')
INSERT INTO #Users VALUES (6,'User6','Kuwait')
INSERT INTO #Users VALUES (7,'User7','USA')
INSERT INTO #Users VALUES (8,'User8','USA')
INSERT INTO #Users VALUES (9,'User9','USA')
INSERT INTO #Users VALUES (10,'User10','USA')

UPDATE #Users 
SET City = 'Kuwait'
WHERE City = 'USA'

SELECT * FROM #Users
DROP TABLE #Users

Output

Id Name City
1 User1 India
2 User2 India
3 User3 Kuwait
4 User4 Kuwait
5 User5 Kuwait
6 User6 Kuwait
7 User7 Kuwait
8 User8 Kuwait
9 User9 Kuwait
10 User10 Kuwait