在 MySQL 中移动和删除行 [英] Moving and Deleting rows in MySQL

查看:47
本文介绍了在 MySQL 中移动和删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MySQL 中创建了两个表,分别称为birthTable"和deathTable".当我在死亡表中添加一个她/他在出生表中的人时,我想从出生表中删除他/她的姓名和家庭,因为我在死亡表中添加了他/她.但我不知道我该怎么做?

I have created two tables in MySQL which are called "birthTable" and "deathTable". When I add a person in deathTable which she/he was in birthTable, I want to delete his/her name and family from birthtable because I add him/her in deathTable. But I don't know how I can do that?

推荐答案

你需要做的是构造一个 DELETE FROM-query.如果您只想从表中删除一行,您需要确保您给它的参数对该行是唯一的.通常这是通过一个名为 id 的列来完成的.然后,知道 id,你所要做的就是:

What you have to do is construct a DELETE FROM-query. If you only want to delete one row from a table, you need to be certain that the parameters you give it are unique for that row. Usually this is done by having a column called id. Then, knowing the id, all you have to do is this:

DELETE FROM table WHERE id=<your id>;

我认为在你的情况下,你可以有一个名为people"的表和一个布尔列alive",如果这个人还活着,它是 1,如果这个人死了,它是 0.

I think that in your case you could just have a table called "people", and a boolean column "alive" which is 1 if the person is alive and 0 if the person is dead.

如果你仍然想从你的birthTable中删除一行,假设你知道这个人的名字,你可以这样做:

If you still want to delete one row from your birthTable, assuming you know the name of this person, you do it like this:

DELETE FROM birthTable WHERE firstName=<first name> AND lastName<last name>;

我假设名字和姓氏的列名是 firstName 和 lastName,您必须修改它以匹配您的列名.这将删除birthTable 中与条件匹配的任何条目(可能不止一个,例如,如果您有两个叫 Alan Johnson 的人).

I've assumed that the column names for first and last names are firstName and lastName, you'll have to modify this to match your column names. This will delete any entry in the birthTable which matches the critera (could be more than one, if you have for example 2 people called Alan Johnson).

希望有所帮助.:)

这篇关于在 MySQL 中移动和删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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