Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table with some data, in this table id in not auto increment. Data is:
Id Name
1 abc
2 def
3 ghi

i want change the series form 1,2,3... to 101,102,103... through query
i want change my table like:
Id Name
101 abc
102 def
103 ghi


Help me to solve that problem
Thanx with Regards
Ankush Sharma
Posted
Comments
_Asif_ 19-Jul-13 1:05am    
Your Id column is primary key?
AnkushSharma100 19-Jul-13 1:06am    
yes, id is a primary key...
_Asif_ 19-Jul-13 1:18am    
How many rows in the table? All Id in the table is increment by 1?
AnkushSharma100 19-Jul-13 1:22am    
Table has more then thousands record...i wanna change all id with increment by 1 and started from 101
ArunRajendra 19-Jul-13 1:08am    
Do you have references to other tables?

try this this will turn your series to the desired
SQL
update subject set subjectid=subjectid+100 
where subjectid=subjectid
 
Share this answer
 
Comments
AnkushSharma100 19-Jul-13 1:44am    
Thanx sir..
Zafar A khan 19-Jul-13 2:59am    
glade to help you
UPDATE table
SET id = 100 + id
FROM table
 
Share this answer
 
declare @temp int
set @temp=0
while(@temp<3)
begin
update tbl set ID=@temp+100+ID where ID=1+@temp
set @temp=@temp+1
end
 
Share this answer
 
Comments
AnkushSharma100 19-Jul-13 1:48am    
Solution of Zafar Safi is very nice..Thanx mr. Zafar Safi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900