接下來的一些內(nèi)容枕面,我們需要提前學(xué)一些簡(jiǎn)單的sql語(yǔ)句,方便大家理解接下來的知識(shí)灵莲。
DDL—數(shù)據(jù)定義語(yǔ)言(Create,Alter殴俱,Drop笆呆,DECLARE)
DML—數(shù)據(jù)操縱語(yǔ)言(Select,Delete粱挡,Update,Insert)
DCL—數(shù)據(jù)控制語(yǔ)言(GRANT俄精,REVOKE询筏,COMMIT,ROLLBACK)
DQL---數(shù)據(jù)查詢語(yǔ)言(select)
DML(data manipulation language):
它們是SELECT竖慧、UPDATE嫌套、INSERT、DELETE圾旨,就象它的名字一樣踱讨,這4條命令是用來對(duì)數(shù)據(jù)庫(kù)里的數(shù)據(jù)進(jìn)行操作的語(yǔ)言
DDL(data definition language):
DDL比DML要多,主要的命令有CREATE砍的、ALTER痹筛、DROP等,DDL主要是用在定義或改變表(TABLE)的結(jié)構(gòu),數(shù)據(jù)類型帚稠,表之間的鏈接和約束等工作上谣旁,他們大多在建立表時(shí)使用
DCL(Data Control Language):
是數(shù)據(jù)庫(kù)控制功能。是用來設(shè)置或更改數(shù)據(jù)庫(kù)用戶或角色權(quán)限的語(yǔ)句滋早,包括(grant,deny,revoke等)語(yǔ)句榄审。在默認(rèn)狀態(tài)下,只有sysadmin,dbcreator,db_owner或db_securityadmin等人員才有權(quán)力執(zhí)行DCL
接下來我們逐步學(xué)習(xí)SQL語(yǔ)句,在學(xué)習(xí)之前我們先注意一下SQL語(yǔ)句的注意事項(xiàng).
1.每條SQL語(yǔ)句結(jié)束時(shí)要以;做為結(jié)束符.(除了use命令)
2.SQL語(yǔ)句的關(guān)鍵字不區(qū)分大小寫(除了庫(kù)名字和表名字)
3.在查詢數(shù)據(jù)庫(kù)信息或者表信息時(shí),可以以\G做為結(jié)束符,表示以文本模式輸出
4.當(dāng)你不需要一條語(yǔ)句輸出的結(jié)果以\c結(jié)束,不可以使用ctrl+c,否則登出mysql.
5.我們可以在命令行執(zhí)行sql語(yǔ)句,要通過mysql -e參數(shù)
mysql -e "show databases /G" 顯示到shell上
6.如果需要獲取SQL語(yǔ)句的幫助可以用help命令
如:help create
如果需要進(jìn)一步獲取幫助,可以繼續(xù)使用help命令
如:help create database
1.DDL數(shù)據(jù)庫(kù)定義語(yǔ)句
建立數(shù)據(jù)庫(kù)以及查詢
create database db;
create database db CHARACTER SET = 'utf8'
show databases;
show create database db;
alter database db CHARACTER SET = 'latin1';
修改庫(kù)名只需要改數(shù)據(jù)庫(kù)目錄名稱
drop database db;
建立表以及查詢
use db
類型
create table t1(id int(6),name char(10));
create table t1(id int(6),name varchar(10));
日期時(shí)間類型
date類型
create table t4(aa date);
insert into t4 values('2010-04-01'),(20100401);
select * from t4;
+------------+
| aa |
+------------+
| 2010-04-01 |
| 2010-04-01 |
+------------+
time類型
create table t5(showttime time);
insert into t5 values ('11:11:11'),('11:11'),('111111');
select * from t5;
+-----------+
| showttime |
+-----------+
| 11:11:11 |
| 11:11:00 |
| 11:11:11 |
+-----------+
出現(xiàn)的問題
create table t6 (a_data data,a_time time);
insert into t6 values('1978-4-6',123412),(651212,'3:5:6');
select * from t6;
+------------+----------+
| a_date | a_time |
+------------+----------+
| 1978-04-06 | 12:34:12 |
| 2065-12-12 | 03:05:06 |
+------------+----------+
年份的范圍00-69為2000-2069&&70-99為1970-1999
year類型
create table t7 (year year);
insert into t7 values(2003),(04),(53),(89),(90);
select * from t7;
+------+
| year |
+------+
| 2003 |
| 2004 |
| 2053 |
| 1989 |
| 1990 |
+------+
datetime和timestamp類型
timestamp 時(shí)間戳類型杆麸,輸入null搁进,顯示當(dāng)前時(shí)間。datetime則會(huì)顯示null
datetime 如果name改變昔头,時(shí)間不改變饼问。例如:QQ的申請(qǐng)時(shí)間
timestamp 如果name改變,時(shí)間會(huì)改變成現(xiàn)在時(shí)間减细。例如:提示上次登錄時(shí)間
values(now()) now()函數(shù)匆瓜,當(dāng)前時(shí)間函數(shù),申請(qǐng)帳號(hào)時(shí)可以觸發(fā)未蝌。
create table t8(f_datetime datetime,f_timestamp timestamp);
insert into t8 values('1999-11-11 11:11:11','2002-11-111:11:11');
insert into t8 values(19991111111111,20021111111111);
insert into t8 values(now(),null);
select * from t8;
+---------------------+---------------------+
| f_datetime | f_timestamp |
+---------------------+---------------------+
| 1999-11-11 11:11:11 | 2002-11-11 11:11:11 |
| 1999-11-11 11:11:11 | 2002-11-11 11:11:11 |
| 2012-03-21 21:05:21 | 2012-03-21 21:05:21 |
+---------------------+---------------------+
ENUM和SET類型
create table t10(sex ENUM('M','F'));
insert into t10 values('M'),('m'),('F'),('aa'),(null);
select * from t10;
+------+
| sex |
+------+
| M |
| M |
| F |
| |
| NULL |
+------+
create table t11 (type SET('a','b','c','d','e'));
insert into t11 values(a);
insert into t11 values('b,c');
insert into t11 values('J');
select * from t11;
+------+
| type |
+------+
| a |
| b,c |
| |
+------+
insert into t11 values('b,c,e,f');既有合法字符又有非法字符
select * from t11;
+-------+
| type |
+-------+
| a |
| b,c |
| |
| b,c,e |
+-------+
練習(xí):
創(chuàng)建表test id name money sex hobby email qq shenfezheng jointime
create table test(id tinyint,name char(10),money float(10,2),sex enum('M','F'),hobby set('a','b','c'),email varchar(50),qq char(15),shenfenzheng char(18),jointime datetime);
mysql> rename table test to newtest;
mysql> alter table test change id uid smallint;
mysql> alter table test modify id smallint;
修飾符(約束)
無符號(hào) unsigned
用0補(bǔ)齊 zerofill
desc t11;
+-------+--------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------------------+------+-----+---------+-------+
| type | set('a','b','c','d','e') | YES | | NULL | |
+-------+--------------------------+------+-----+---------+-------+
not null約束
create table t12 (id int,sex enum('M','W') NOT NULL );
desc t12;
+-------+---------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+-------+
| id | int(10) unsigned zerofill | YES | | NULL | |
| sex | enum('M','W') | YES | | NULL | |
+-------+---------------------------+------+-----+---------+-------+
insert into t12(id) values(1);
Query OK, 1 row affected (0.00 sec)
select * from t12;
+---+-----+
|id | sex |
+---+-----+
| 1 | NULL|
+---+-----+
DEFAULT約束
create table t13 (id int ,sex enum('M','W') NOT NULL default 'M' );
desc t13;
+-------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| sex | enum('M','W') | YES | | M | |
+-------+---------------+------+-----+---------+-------+
insert into t13(id) values(3);
select * from t13;
+------+------+
| id | sex |
+------+------+
| 2 | M |
| 3 | M |
+------+------+
AUTO_INCREMENT修飾符自動(dòng)增長(zhǎng)只適用于int字段 一般用于主鍵 一個(gè)表只能有一個(gè)
create table t14(id int auto_increment primary key,name char(10) not ll);
desc t14
+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | char(10) | NO | | NULL | |
+-------+----------+------+-----+---------+----------------+
insert into t14(name) values(zhb);
insert into t14(name) values('haha');
select * from t14;
+----+------+
| id | name |
+----+------+
| 1 | zhb |
| 2 | haha |
+----+------+
索引添加刪除
show index from t20\G
show create table t20;
drop index index_name on table_name;
create index index_name on table_name(列名);
alter table table_name add index(列名);
索引建立
create table t15(id int not null ,name char(10),index(id));
desc t15;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | MUL | NULL | |
| name | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
向已有表添加索引
create table t16(id int not null ,name char(10));
desc t16;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | | NULL | |
| name | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
create index id on t16 (id);
alter table t17 add index(id);
desc t16;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | MUL | NULL | |
| name | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
刪除索引
drop index id on t16;
desc t16;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | | NULL | |
| name | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
查詢索引
show index from t16;
UNIQUE索引(允許空值,null != null)
create unique index id on table_name(id);
create table t17(id int ,name char(10),unique(id));
desc t17;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | UNI | NULL | |
| name | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
insert into t17 values(null,'zhb');
select * from t17;
+------+------+
| id | name |
+------+------+
| NULL | zhb |
+------+------+
PRIMARY KEY(主鍵約束 值唯一 uniq和not null的結(jié)合 可作用多列 不可兩列同時(shí)相同驮吱,單列重復(fù)可以)
alter table t22 drop primary key;
alter table t22 add primary key(id);
create table t18(id int,name char(10),primary key(id));
desc t18;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | PRI | 0 | |
| name | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
insert into t18 values(1,'zhb');
select * from t18;
+----+------+
| id | name |
+----+------+
| 1 | zhb |
+----+------+
insert into t18 values(1,'zhb');
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY' 不允許重復(fù)
刪除主鍵
mysql> alter table t19 drop primary key;
向已有表添加主鍵
mysql> alter table t19 add primary key(id);
在多個(gè)列上建立主鍵,不可多次添加主鍵
create table t19(id int,name char(10),primary key(id,name));
desc t19;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | PRI | 0 | |
| name | char(10) | NO | PRI | | |
+-------+----------+------+-----+---------+-------+
insert into t19 values(1,'zhb');
insert into t19 values(1,'zorro');
select * from t19;
+----+-------+
| id | name |
+----+-------+
| 1 | zhb |
| 1 | zorro |
+----+-------+
外鍵myisam引擎不支持只能用innodb引擎
create table dpmnt(id int not null,name char(10) not null,primary key(id)) type = INNODB;
desc dpmnt;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | char(10) | NO | | NULL | |
+-------+----------+------+-----+---------+-------+
建立外鍵
create table emp (id int not null, name char(10) not null,fk_dpmnt int not null ,primary key(id),index (fk_dpmnt),foreign key (fk_dpmnt) references dpmnt(id)) type=innodb;
desc emp;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | char(10) | NO | | NULL | |
| fk_dpmnt | int(11) | NO | MUL | NULL | |
+----------+----------+------+-----+---------+-------+
insert into dpmnt values(1,hr);
insert into dpmnt values(2,'yw');
insert into emp values(10,'zhb',3);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (db
.emp
, CONSTRAINT emp_ibfk_1
FOREIGN KEY (fk_dpmnt
) REFERENCES dpmnt
(id
))
fk_dpmnt字段的數(shù)據(jù)必須得是dpmnt表里有的不然報(bào)錯(cuò)...
即使表存在外鍵約束,MySQL還允許我們刪除表萧吠,并且不會(huì)產(chǎn)生錯(cuò)誤左冬。這是刪除外鍵的方法。
alter table emp drop foreign key emp_ibfk_1;
刪除外鍵
全文本索引
mysql> desc t22;
create table t22(id int,name char(10),fulltext(name));
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(10) | YES | MUL | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.01 sec)
練習(xí):
創(chuàng)建表test id name money sex hobby email qq shenfezheng jointime
create table test(id tinyint,name char(10),money float(10,2),sex enum('M','F'),hobby set('a','b','c'),email varchar(50),qq char(15),shenfenzheng char(18),jointime datetime);
1.添加約束
create table test1 ( id int primary key auto_increment, name char(20) not null, money float(10,2) not null, sex enum('M','F') not null default 'M', hobby set('a','b','c') not null default 'a', qq char(15) unique, email char(50), jointime datetime,index(email));
2.刪除掉所有的約束
alter table test1 modify id int; 刪除auto_increment
alter table test1 drop primary key; 刪除primary key
alter table test1 modify id int; 刪除 not null
alter table test1 modify name char(10);
alter table test1 modify money float(10,2);
alter table test1 modify sex enum('M','F');
alter table test1 modify hobby set('a','b','c');
drop index qq on test1;
drop index email on test1;
3.在添加約束
alter table test1 add primary key(id);
alter table test1 modify id int auto_increment;
show tables;
show create table t1;
ALTER table t2 RENAME t1;
alter table t2 MODIFY a tinyint not null,CHANGE b c char(20);
mysql> alter table test2 modify id tinyint,change name testname char(30); 重命名時(shí)名字不能是關(guān)鍵字纸型,rename等
mysql> alter table tt2 change id did int;
create table members ( id int(11),name char(10),tel char(15));
alter table members ADD qq int;
alter table members drop qq;
alter table members add qq int after name ;
alter table members add phone first;
alter table test1 modify qq char(15) after id;
drop table t1;
2.DML 數(shù)據(jù)庫(kù)操縱語(yǔ)句
insert
mysql> INSERT INTO members ( member_id,fname,lname,tel,email) VALUES ( NULL,'john','Doe','1234567','jdoe@163.com');
mysql> INSERT INTO members VALUES ( NULL,'kyo','oyk','7654321','kyo@163.com');
mysql> INSERT INTO members (fname,lname,email,tel,member_id) VALUES ('bob','kk','bob@163.com','22334455',NULL);
update
mysql> UPDATE members SET email = 'kyo@163.com' WHERE member_id = 3;
mysql> UPDATE members SET email = 'hoho@163.com',lname = 'ho' WHERE member_id = 2;
delete
mysql> DELETE FROM members;
mysql> DELETE FROM members WHERE member_id = 1;
sql語(yǔ)句使用
連接數(shù)據(jù)庫(kù)
mysql -u root -p123 -h localhost
查看服務(wù)器狀態(tài)
show staus;
顯示所有庫(kù)名
show databases;
使用數(shù)據(jù)庫(kù)
use db;
顯示當(dāng)前數(shù)據(jù)庫(kù)中的所有表
show tables;
查看表結(jié)構(gòu)
desc tables;
select查詢語(yǔ)句(默認(rèn)亂序拇砰,可以指定多列顯示順序)
select name from tables; 從表中查詢指定列
select id,name,sal from tables; 指定多個(gè)列名
select * from tables;查詢所有的列
select distinct id from tables; 去掉重復(fù)行
select name from tables limit 5; 顯示前5行
select name from tables limit 5,5;顯示從第5行開始的后5行即5-10行
select name from db.t1;沒有使用use進(jìn)入db庫(kù)時(shí)查詢db庫(kù)的t1表
select t1.name from db.t1; 指定庫(kù)的表 指定表的列
顯示mysql中第一個(gè)用戶名字?
在shell命令行顯示用戶的名字和密碼
顯示mysql中的前3個(gè)用戶
修改root帳號(hào)密碼為456
[root@uplooking 桌面]# /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables &
mysql> update mysql.user set password=password('123456') where user='root' and host='localhost';
[root@uplooking 桌面]# killall mysqld
[root@uplooking 桌面]# service mysqld restart
[root@uplooking 桌面]# /usr/local/mysql/bin/mysql -uroot -p123456
排序檢索語(yǔ)句
select id,name from t1 order by id; 按id排序
select id,name from t1 order by id,name;先按id排序id相同在按name排序
select id,name from t1 order by id desc; 按id反向排序
select id,name from t1 order by id desc,name; 先按id反向排序再按名字排序
select id,name,sal from t1 order by sal desc limit 1;查找工資最高的人
where子句
select id,name,sal from t1 where name='tom'; 查找tom的信息
where 子句的操作符
= 等于
<> 不等于
!= 不等于
< 小于
<= 小于等于
大于
= 大于等于
between 5 and 10 在兩個(gè)值之間
is null 空值
is not null 非空值
select id,name from t1 where id>5 and name='tom'; and操作符表示兩個(gè)條件都要滿足 與操作
select id,name from t1 where id=10 or name='tom';or操作符表示滿足任意條件 或操作
select id,name,sal from t1 where id=10 or id=20 and sal > 5000; id為10的 或者id為20并且薪水大于5000的;and優(yōu)先執(zhí)行
select id,name,sal from t1 where (id=10 or id=20) and sal > 5000;id為10或者20 并且薪水大于5000的
select id,name,sal from t1 where id in (10,20,30);id在 10 20 30 中的記錄
這條語(yǔ)句用or可以做到相同的結(jié)果,那in的好處
1.in的語(yǔ)法更加直觀
2.in的計(jì)算次序更容易管理(操作符少)
3.in 一般比or執(zhí)行的更快
4.in的最大優(yōu)點(diǎn)可以包含其他子句 or不行
取最高薪水的人
select * from test2 where money=(select money from test2 order by money desc limit 1);
select * from test where id=(select id from test order by id desc limit 1); id號(hào)最高的人
復(fù)制表結(jié)構(gòu)
create table test1 as select * from test where 1>2; 只復(fù)制表結(jié)構(gòu),不復(fù)制數(shù)據(jù)
create table test2 as select * from test; 完全復(fù)制狰腌,包括數(shù)據(jù)
select id,name,sal from t1 where id not in (10,20,30); id不在10 20 30的記錄 not找到不匹配的記錄更簡(jiǎn)單
通配符%匹配多個(gè)字符_匹配一個(gè)字符
select id,name from t1 where name like 'jer%';模糊查詢名字為jer開頭的記錄
select id,name from t1 where name like 'j%y'; 匹配j開頭y結(jié)尾的
select id,name from t1 where name like '_err%' 匹配e前邊有一個(gè)字符的記錄
原則:
盡量少使用通配符,如果其他操作符能做到就不要使用通配符
在確實(shí)需要通配符時(shí),盡量不要使用%erry 這種用法搜索起來會(huì)更慢
至于使用位置,使用錯(cuò)了得不到想要的結(jié)果
正則表達(dá)式的使用regexp
select id,name from t1 where name regexp 'je*';調(diào)用正則匹配je開頭
select id,name from t1 where name regexp 'y$';
語(yǔ)句的拼接
select concat(id ,'(',name,')') from t1 將id和name 拼接為1列 oracle用||
select concat(id ,'(',name,')') all_name from t1 別名也可以使用as
select sal*12 from t1 計(jì)算全年薪水 + - * /
函數(shù)使用
select upper(name) as new_name from t1; 將名字轉(zhuǎn)換為大寫 lower 小寫
group by 分組 必須在where之后 分組前過濾 having 可以分組后過濾
sum max min avg count year month day hour minute second
select count() from emp group by sex;
select count() as num emp group by id having num > 3;
where 條件必須在group by前面除破,having可以在group by 后面
1.建立員工檔案表
要求字段:?jiǎn)T工員工編號(hào),員工姓名琼腔,性別瑰枫,工資,email丹莲,入職時(shí)間光坝,部門。
create table emp(uid int primary key auto_increment,name char(10) not null,sex enum('M','F') not null default 'M',money float(10,2),email varchar(50),jointime datetime,dname char(20),unique(email));
2.合理選擇數(shù)據(jù)類型及字段修飾符甥材,要求有NOT NULL盯另,auto_increment, primary key等。
3.查看表的結(jié)構(gòu)
desc emp;
4.新增qq和tel字段洲赵,要求tel字段位于email前鸳惯,要求入職時(shí)間是最后一個(gè)字段
alter table emp add tel char(11) after money;
alter table emp add qq char(15);
alter table emp modify jointime datetime after qq;
5.把email字段修改成mailbox
alter table emp change email mailbox varchar(50)
6.向表里添加10條記錄
7.修改其中兩條記錄的tel和mailbox
update emp set tel=18611112222 where name='lici';
update emp set mailbox='lici@lici.com' where name='lici';
8.查看所添加記錄
9.查看姓名和入職時(shí)間記錄
10.查詢?nèi)肼殨r(shí)間在2003年以前的
select name,jointime from emp where year(jointime)<2013;
11.查詢工資最高和最低的員工姓名
select name,money from emp where money=(select min(money) from emp);
select name,money from emp where money=(select max(money) from emp);
12.查詢平均工資
13.統(tǒng)計(jì)男員工人數(shù)商蕴、女員工人數(shù)
select count(*) from emp group by sex;
14.按照入職時(shí)間先后進(jìn)行排序,并顯示前5位員工姓名
select * from emp order by jointime limit 5;
筆記補(bǔ)充:
create table t3 (id int unsigned); unsigned取值范圍無符號(hào)(0,255)
char(10) 長(zhǎng)度 int(6) zerofill 不足6位前面用0自動(dòng)補(bǔ)齊悲敷,例如:?jiǎn)T工號(hào)
oracle的 OLAP數(shù)據(jù)庫(kù) 寫入少究恤,讀多 carchar利用率高 。 OLTP在線數(shù)據(jù)庫(kù)后德,比較多的更改用char
ENUM和SET 枚舉類型
enum單選部宿,可以為空 例如性別 set 多選 喜愛
UNIQUE 不可以重復(fù)值,但是可以為空瓢湃。null 理张!= null
create unique index ID on t1(ID);
primary key 可以用多格列绵患,不允許兩個(gè)列
外鍵:部門did約束雾叭,員工did范圍不超過部門did
幻讀:事物提交之前讀取的數(shù)據(jù)
臟讀:在內(nèi)存中,未寫到硬盤中而讀取的數(shù)據(jù)
start transaction落蝙; 開啟事物织狐。開啟后,insert數(shù)據(jù) 再create筏勒,會(huì)自動(dòng)提交數(shù)據(jù)移迫。不再同一終端可以create,不會(huì)提交管行。例如:申請(qǐng)賬號(hào)厨埋,返回,上一步等選項(xiàng)