對MySql刪除資料操作

2021-08-13 11:42:02 字數 2536 閱讀 1325

學習任務

使用sql語句刪除姓名為jerry的人

左邊圖右邊圖學習目標

知識目標

1.      熟悉sql的刪除記錄語句

2.      熟悉對mysql資料庫的刪除操作

3.       

能力目標

1.      能夠對資料庫進行刪除操作

刪除語句

deletefrom 【表名】where 【列名】 like '【檢索的條件】
1.連線資料庫

conn  用於建立資料的連線

cur  通過獲取到的資料庫連線conn下的cursor()方法來建立游標

2.執行刪除操作

第一句   編寫sql語句

第二句   執行sql語句【通過游標

cur 

操作execute()

方法可以寫入純

sql語句。對資料進行操作。】

2.      關閉資料庫連線

3.      

示例
使用sql語句刪除符合查詢調價的資料

任務實施

錄屏
知識點總結
1.  使用sql語句刪除資料
2.  連線mysql資料庫
問題
1.  刪除表中名字為admin的記錄

2.  同時刪除表中名字為lihua和liliang的記錄

3.  對資料庫刪除操作的sql語句格式是什麼
答案
1.
#!/user/bin/env python

# _*_ coding:utf-8 _*_

#coding=utf-8

import mysqldb

conn= mysqldb.connect(

host='localhost',

port = 3306,

user='root',

passwd='123456',

db ='test',

)cur = conn.cursor()

sql ="delete from user where name='admin'";

cur.execute(sql);

cur.close()

conn.commit()

conn.close()

2.

#!/user/bin/env python

# _*_ coding:utf-8 _*_

#coding=utf-8

import mysqldb

conn= mysqldb.connect(

host='localhost',

port = 3306,

user='root',

passwd='123456',

db ='test',

)cur = conn.cursor()

sql1 = "delete from userwhere name like 'li*'";

cur.execute(sql1);

cur.close()

conn.commit()

conn.close()

3.delete from 【表名】where 【列名】 like '【檢索的條件】'

MySQL刪除資料

mysql通過delete從表中刪除 去掉 資料。可以從表中刪除特定的行或者從表中刪除所有的行。下面語句是從customer表中刪除一行 delete from customers where cust id 10006 先檢視表customers在刪除前的成員 select cust id,cus...

MySQL 刪除資料

從資料表中刪除資料使用 delete 語句,delete 語句允許用 where 子句指定刪除條件。語法格式 delete from table name where table name 要執行刪除操作的表 where 為可選引數,用於指定刪除條件,如果沒有 where 子句,將刪除表中的所有記錄...

MYSQL刪除資料

884 535 qq.com 一 mysql 刪除表的幾種情況 1 drop table table name 刪除表全部資料和表結構,立刻釋放磁碟空間,不管是 innodb 和 myisam 例項,刪除學生表 drop table student 2 truncate table table na...