Click here to Skip to main content
15,904,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
eg:-
this table Emplyoee
ID NAME
1 amol
2 ram
3 ganesh


this table id not assign primary key.perform delete operation in this table
when delete the record id should be still constant the name should be delete and
other name assign the id

eg

ID NAME
1 amol
2 ram
3 ganesh


when delete operation perform this table look this

ID NAME
1 ram
2 ganesh
3 ashok
how to solve the this problem in sql server 2005
Posted

1 solution

Hi, please find below code as exactly what u need it..

SQL
UPDATE dbo.Emp SET EmpName = t1.EmpName 
FROM (SELECT e.EmpId,e1.EmpName FROM dbo.Emp e LEFT OUTER JOIN dbo.Emp e1
on e.EmpID + 1 = e1.EmpID ) t1
WHERE dbo.Emp.EmpId = t1.EmpId


Thanks,
 
Share this answer
 

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