mysql資料庫增刪改操作

2021-09-17 22:39:04 字數 1572 閱讀 9040

insert into 表名(列名1,列名2,列名3) values(值1,值2,值3);

insert into user(user_id,name,age) values(1,『nice』,24);

delete from 表名 [where 條件]

update 表名 set 列名=列的值,列名2=列2的值 [where條件]

1、資料庫增加資料:

1)插入單行

insert [into] 《表名》 (列名) values (列值)

例:insert into t_table (name,***,birthday) values (『開心朋朋』,『男』,『1980/6/15』)

2)將現有表資料新增到乙個已有表 insert into 《已有的新錶》 (列名) select 《原表列名》 from 《原表名》

select name,address,email from t_table

3)直接拿現有表資料建立乙個新錶並填充 select 《新建表列名》 into 《新建表名》 from 《源表名》例:select name,address,email into t_table from strde

2、資料庫刪除資料:

1)刪除《滿足條件的》行

delete from 《表名》 [where 《刪除條件》]。

例:delete from t_table where name=『開心朋朋』(刪除表t_table中列值為開心朋朋的行)

2)刪除整個表 truncate table 《表名》

truncate table tongxunlu

注意:刪除表的所有行,但表的結構、列、約束、索引等不會被刪除;不能用語有外建約束引用的表
3、資料庫修改資料 update 《表名》 set 《列名=更新值》 [where 《更新條件》]

例:update t_table set age=18 where name=『藍色小名』

4、資料庫查詢資料:

1)精確(條件)查詢

select 《列名》 from 《表名》 [where 《查詢條件表達試》] [order by 《排序的列名》[asc或desc]]

2)查詢所有資料行和列。例:select * from a

說明:查詢a表中所有行和列

3)使用like進行模糊查詢

注意:like運算副只用於字串,所以僅與char和varchar資料型別聯合使用
例:select * from a where name like 『趙%』

說明:查詢顯示表a中,name欄位第乙個字為趙的記錄

4)使用between在某個範圍內進行查詢

例:select * from a where nianling between 18 and 20

說明:查詢顯示表a中nianling在18到20之間的記錄

5)使用in在列舉值內進行查詢

例:select name from a where address in (『北京』,『上海』,『唐山』)

說明:查詢表a中address值為北京或者上海或者唐山的記錄,顯示name欄位

Python 資料庫,操作mysql,增刪改

demo.py 增 刪 改 匯入pymysql模組 from pymysql import 需要pip3 install pymysql 安裝模組。python2.x中用的是mysqldb模組 def main 建立connection連線 conn connect host localhost p...

詳解mysql資料庫增刪改操作

插入資料 insert into 表名 列名1程式設計客棧,列名2,列名3 values 值1,值2,值3 insert into user user id,name,age values 1,nice 24 簡單寫法可以省去欄位名,但是要插入全部字段。批量插入 單條插入和程式設計客棧批量插入的效率...

PHP操作MySQL資料庫(連線 增刪改操作)

mysql 是跟 php 配套使用的最流行的開源資料庫系統,我們知道mysql是php的最佳搭檔,下面是系統的總結php與mysql聯合使用的方法。主要是使用mysql擴充套件,下面就通過歸納總結來提公升。mysql 是一種在 web 上使用的資料庫系統。mysql 是一種在伺服器上執行的資料庫系統...