国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL學習筆記之數據的增、刪、改實現方法

2024-07-24 12:53:42
字體:
來源:轉載
供稿:網友

本文實例講述了MySQL學習筆記之數據的增、刪、改實現方法。,具體如下:

一、增加數據

插入代碼格式:

insert into 表明 [列名…] values (值…)

create table test21(name varchar(32));insert into test21 (name) values ('huangbiao');

插入原則:

1、插入的數據應與字段的數據類型相同
2、數據的大小應該在列的規定范圍內
3、在values中列出的數據位置必須與被加入的列的排列位置對應

例子:

create table test22(id int,name varchar(32));mysql> insert into test22 (id,name) values (3,'huangbiao');mysql> insert into test22 (name,id) values ('huangbiao2',5);mysql> insert into test22 (name,id) values ('',51);mysql> insert into test22 (name,id) values (NULL,555);mysql> insert into test22 (id) values (15);

二、更新數據

更新數據的語法格式:

update 表明 set 列名=表達式 … where 條件

說明: 如果where 后面沒有條件,則相當于對整個表進行操作。

例子數據:

create table employee( id int, name varchar(20), sex bit, birthday date, salary float, entry_date date, resume text);insert into employee values(1,'aaa',0,'1977-11-11',56.8,now(),'hello word');insert into employee values(2,'bbb',0,'1977-11-11',57.8,now(),'hello word');insert into employee values(3,'ccc',0,'1977-11-11',56.3,now(),'hello word');

將employee表的sal字段全部改為2000

update employee set sal=2000;

將名字為zs的用戶的sal字段設置為3000

update employee set sal=3000 where name='zs'

將名字為wu的用戶sal字段在原來的基礎上加100

update employee set sal=sal+100 where name='wu'

三、刪除數據

刪除數據語法:

delete from 表明 where 條件

刪除數據原則:

1、 如果不使用where 子句,將刪除表中所有數據
2、 delete語句不能刪除某一列的值(可使用update)
3、 delete僅僅刪除記錄,不刪除表本身,如要刪除表,使用drop table語句
4、 同insert和update一樣,從一個表中刪除一條記錄將引起其他表的參照完整性問題
5、 刪除表中的數據也可以使用truncate table語句

mysql 事務

1、 mysql控制臺是默認自動提交事務(dml)
2、 如果我們要在控制臺中使用事務,請看下面:

mysql 刪除數據是自動提交的

mysql> set autocommit=false;Query OK, 0 rows affected (0.00 sec)mysql> savepoint aaa;Query OK, 0 rows affected (0.00 sec)mysql> delete from employee;Query OK, 3 rows affected (0.05 sec)mysql> select * from employee;Empty set (0.00 sec)mysql> rollback to aaa;Query OK, 0 rows affected (0.06 sec)mysql> select * from employee;+------+------+------+------------+--------+------------+------------+| id | name | sex | birthday | salary | entry_date | resume |+------+------+------+------------+--------+------------+------------+| 1 | aaa | | 1977-11-11 | 56.8 | 2014-11-10 | hello word || 2 | bbb | | 1977-11-11 | 57.8 | 2014-11-10 | hello word || 3 | ccc | | 1977-11-11 | 56.3 | 2014-11-10 | hello word |+------+------+------+------------+--------+------------+------------+3 rows in set (0.00 sec)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丹阳市| 漳浦县| 新河县| 平远县| 榆林市| 龙川县| 简阳市| 金湖县| 新巴尔虎右旗| 大荔县| 台中市| 瑞丽市| 常德市| 江津市| 分宜县| 北碚区| 定州市| 鄱阳县| 高邑县| 兴国县| 株洲市| 庆阳市| 松阳县| 盐池县| 广昌县| 同江市| 诏安县| 固始县| 景德镇市| 柳州市| 西吉县| 望城县| 收藏| 诸暨市| 抚宁县| 邹平县| 衡阳县| 樟树市| 锡林浩特市| 东兰县| 西乡县|