在表2中,不应删除在表ID上执行的字段ID和名称删除操作,但名称应移位1 [英] in table two field id and name delete operation perform on table id should not be delete but name is shifted by one
问题描述
例如:-
这张桌子Emplyoee
ID NAME
1 amol
2公羊
3 ganesh
该表ID未分配主键.在此表中执行删除操作
当删除记录ID时仍应保持不变,名称应删除并
其他名称分配ID
例如
ID NAME
1 amol
2公羊
3 ganesh
删除操作执行此表时,请查看此
ID NAME
1公羊
2 ganesh
3 ashok
如何在sql server 2005中解决此问题
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
推荐答案
您好,请在下面的代码中找到您真正需要的代码..
Hi, please find below code as exactly what u need it..
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,
这篇关于在表2中,不应删除在表ID上执行的字段ID和名称删除操作,但名称应移位1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!