Home >Database >Mysql Tutorial >mysql教程删除数据sql语句用法

mysql教程删除数据sql语句用法

WBOY
WBOYOriginal
2016-06-07 16:20:591320browse

mysql教程删除数据sql语句用法 DELETE FROM 语句用于从数据库表中删除记录。 语法 DELETE FROM table_name WHERE column_name = some_value 注释:SQL 对大小写不敏感。DELETE FROM 与 delete from 等效。 为了让 PHP 执行上面的语句,我们必须使用 mysql_qu

   mysql教程删除数据sql语句用法

  DELETE FROM 语句用于从数据库表中删除记录。

  语法

  DELETE FROM table_name WHERE column_name = some_value

  注释:SQL 对大小写不敏感。DELETE FROM 与 delete from 等效。

  为了让 PHP 执行上面的语句,我们必须使用 mysql_query( 函数。该函数用于向 SQL 连接发送查询和命令。

  例子

  稍早时,,我们在本教程中创建了一个名为 "Person" 的表。它看起来类似这样:

  FirstName LastName Age

  Peter Griffin 35

  Glenn Quagmire 33

  下面的例子删除 "Person" 表中所有 LastName='Griffin' 的记录:

  $con = mysql_connect("localhost","peter","abc123");

  if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

  mysql_select_db("my_db", $con);

  mysql_query("DELETE FROM Person WHERE LastName='Griffin'");

  mysql_close($con);

  ?>

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

  FirstName LastName Age

  Peter Griffin 35

        :更多精彩文章请关注三联编程教程栏目。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn