使用已删除的主键 [英] Using Deleted primary key

查看:82
本文介绍了使用已删除的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有一个表格XYZ,其中包含一列srno。它没有约束,没有序列,没有触发器,我假设srno是唯一的。该表与任何其他表无关。



我的客户端要求删除行时,应删除已删除的srno。



如何使用SQL Query完成此操作。

直到现在我正在使用

Hello,
I have a table XYZ which contains a column "srno". It has no constraint(s), no Sequences, no trigger, I have assumed that the srno is unique. The table has no relation with any other table.

My client has a requirement that when a row is deleted, The deleted "srno" should be reused.

How can I accomplish this using SQL Query.
Till now I am using

select max(nvl(Srno,0))+1 from xyz

找出新的SRNO,它将返回Re的丢失或删除的srno - 使用!



Prathamesh

to Find out the new SRNO which will return the missing or deleted srno for Re-Use!

Prathamesh

推荐答案

我会将删除的SRNO插入到另一个表中,如果是那个表行使用该表中的SRNO(完成后删除它)。如果没有行,您可以使用上面概述的方法。
I would insert the deleted SRNO into another table and if that table has rows use an SRNO from that table (delete it when done). If it has no rows you can use the method you outlined above.


有两种方法,您可以将新记录添加到已删除的缺失srno,例如,如果您有1到10条记录顺序1,2,3等srno你正在删除第三个srno,现在你要插入新记录,然后首先需要找出丢失的srno并在插入新条目时使用该srno。 br />






如果你想要这样的东西,1,2,3 ... 10和你正在删除第3个srno然后其余的条目会自动调整,正确的顺序如1,2,3,4,5,6,7,8,9,所以为此你需要每次更新正确的srno来激活更新查询删除任何记录时的其余记录。
there are two ways, you can add new records to missing srno which is deleted, like if you have 1 to 10 records having srno in sequence 1,2,3 etc. and you are deleting the 3rd srno, and now you are inserting new record then first of all you need to find out the missing srno and use that srno while you are inserting new entry.

or

if you want something like this, 1,2,3...10 and you are deleting 3rd srno then rest of the entries are auto adjust with proper sequence like 1,2,3,4,5,6,7,8,9, so for this you need to fire update query every time to update proper srno to rest of the records whenever you are deleting any record.


这篇关于使用已删除的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆