如何在不影响其他值的情况下获取空值来代替序列中已删除的行 [英] How to obtain null values in place of deleted rows in a sequence without affecting other values

查看:54
本文介绍了如何在不影响其他值的情况下获取空值来代替序列中已删除的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

create table missing_data(sno varchar(3)primary key,name varchar(15),designation char(10))

insert into missing_data values(1,'riz','SE'),(2,'sandy','SE'),(3,'sharein','SE'),(4,'chithu','SE'),(5,'flora','SE'),(6,'gayu','SD'),(7,'maha','SD'),(8,'moni','SD'),(9,'maddy','AE'),(10,'naz','AE')

select * from missing_data order by sno

delete from missing_data where name='gayu' 





我尝试了什么:



我在上面删除了name ='gayu'表和我希望sno = 6在使用null va删除后出现在表上行中的lues不会影响序列..这可能在sql表中???



What I have tried:

I had deleted name='gayu' in the above table and i want sno = 6 to appear on the table after delete with null values in the row without affecting sequence.. is that possible in sql table???

推荐答案

你永远不想重用ID。如果删除一行,那么该ID就会消失,再次使用它是非常糟糕的做法。相反,如果您不想删除它,请添加名为deleted_time的字段并存储删除的时间。然后在检索数据时过滤掉那些。
You don't ever want to reuse Ids. If you delete a row then that ID is gone and it is very bad practice to use it again. Instead, if you don't really want it deleted, add a field named deleted_time and store the time it is deleted. Then filter those out when retrieving your data.


这篇关于如何在不影响其他值的情况下获取空值来代替序列中已删除的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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