在Mysql中delete和update命令如何工作?

时间:2015-07-31 05:28:26

标签: mysql sql

在mysql数据库中我有一个表:

+---------+------------------+------+-----+---------+----------------+
| Field   | Type             | Null | Key | Default | Extra          |
+---------+------------------+------+-----+---------+----------------+
| user_id | int(20) unsigned | NO   | PRI | NULL    | auto_increment |
| NAME    | varchar(20)      | YES  |     | NULL    |                |
| email   | varchar(20)      | NO   | PRI |         |                |
+---------+------------------+------+-----+---------+----------------+

我有数据:

+---------+--------+------------------+
| user_id | NAME   | email            |
+---------+--------+------------------+
|       1 | ap      | aa1@aol.com     |
|       3 | as      | aap@aol.com     |
|       4 | salini | salini@gmail.com |
+---------+--------+------------------+

现在我的要求: 我想一次删除并设置一行的值..

假设我要删除名称并更新email='saliniRoy@gmail.com,其中name = salini

所以我正在使用

UPDATE student
SET email='saliniRoy@gmail.com' & delete name
WHERE name=salini;

但它不起作用......我必须做什么呢?

1 个答案:

答案 0 :(得分:3)

您必须将名称设置为空白:

UPDATE student
SET email='saliniRoy@gmail.com', name=''
WHERE name='salini';

null

UPDATE student
SET email='saliniRoy@gmail.com', name=null
WHERE name='salini';