枫叶落
Mysql删除记录(delete from)
2014-7-10 Eagle

delete from命令用于删除表中的数据。

delete from命令格式:delete from 表名 where 表达式

例如,删除表 MyClass中编号为1 的记录:
    mysql> delete from MyClass where id=1;

请对比一下删除数据前后表的变化。


FirstName

LastName

Age

Peter

Griffin

35

Glenn

Quagmire

33


下面以PHP代码为例删除 "Persons" 表中所有 LastName='Griffin' 的记录:

<?php 
$con = mysql_connect("localhost","peter","abc123"); 
if (!$con){die('Could not connect: ' . mysql_error()); 

mysql_select_db("my_db", $con); 
mysql_query("DELETE FROM Persons WHERE LastName='Griffin'"); mysql_close($con); 
?>

在这次删除之后,表是这样的:


FirstName

LastName

Age

Glenn

Quagmire

33
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容