如何删除表中主键的中间行? [英] How to delete middle row with primary key in a table?

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

问题描述



我有一个SQL表用户。它有3列id(设置为主列,Is Identity为Yes),名称和密码。当我向表格输入数据时,id会增加。但是在删除查询时,只会删除名称和密码。我需要删除包含id的特定行。例如:



id:1名称:abc密码:123

id:2名称:密码:234

id:3名称:lkj密码:222

id:4名称:新密码:999


我需要删除第三个列ie,

id:3名称:lkj密码:222

但删除此行后,表格应如下所示。



id:1名称:abc密码:123

id:2名称:密码:234

id:3名称:新密码:999

推荐答案

为什么还要重新分配ID?主id密钥用于确保数据库系统中该表中每条记录的唯一性。它们是自动生成的,你应该不管它们。没有理由改变它(出于美观的原因?)。此外,它是一个密码表,您不希望任何人访问它。
Why do you bother to re-assign the ids? The primary id key is there to ensure the uniqueness of each record in that table by the database system. They are auto-generated and you shall leave them alone. There is really no reason to change it (for cosmetic reason?). Furthermore, it is an password table that you do not want any one to have access to it.


您可以尝试这个,它将从您的表中删除id为3列的记录:

You can try this, it will delete from your table the record which has 3 in id column:
DELETE yourTableName WHERE id = 3;





如果您想更新您的表的ID,但要注意与外表的关系。如果您在数据库中的其他位置使用此表中的ID,则可能会导致一些故障。



It can be possible if you would like to update the ID's of your table but be aware of the relation with your foreign tables. If you use your ID from this table somewhere else in the database it can cause some malfunction.


这篇关于如何删除表中主键的中间行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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