zoukankan      html  css  js  c++  java
  • 【练习】使用事务控制语句

    1.使用show engines 命令确定系统中是否有任何事务存储引擎可用以及哪个是默认引擎。

    2.使用set autocommit 语句启用autocommit。

    3.为使用world数据库做准备,确认city表使用事务存储引擎innodb。

    4.使用start transaction 语句显式启动新事务。

    5.删除一行。

    6.使用rollback语句回滚打开的事务。

    1.

    mysql> show enginesG
    *************************** 1. row ***************************
          Engine: PERFORMANCE_SCHEMA
         Support: YES
         Comment: Performance Schema
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 2. row ***************************
          Engine: CSV
         Support: YES
         Comment: CSV storage engine
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 3. row ***************************
          Engine: MRG_MYISAM
         Support: YES
         Comment: Collection of identical MyISAM tables
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 4. row ***************************
          Engine: BLACKHOLE
         Support: YES
         Comment: /dev/null storage engine (anything you write to it disappears)
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 5. row ***************************
          Engine: MyISAM
         Support: YES
         Comment: MyISAM storage engine
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 6. row ***************************
          Engine: MEMORY
         Support: YES
         Comment: Hash based, stored in memory, useful for temporary tables
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 7. row ***************************
          Engine: ARCHIVE
         Support: YES
         Comment: Archive storage engine
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 8. row ***************************
          Engine: InnoDB
         Support: DEFAULT
         Comment: Supports transactions, row-level locking, and foreign keys
    Transactions: YES
              XA: YES
      Savepoints: YES
    *************************** 9. row ***************************
          Engine: FEDERATED
         Support: NO
         Comment: Federated MySQL storage engine
    Transactions: NULL
              XA: NULL
      Savepoints: NULL
    9 rows in set (0.00 sec)

    2.

    mysql> set autocommit = 1;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select @@autocommit;
    +--------------+
    | @@autocommit |
    +--------------+
    |            1 |
    +--------------+
    1 row in set (0.00 sec)

    3.

    mysql> use world
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    
    mysql> show create table cityG
    *************************** 1. row ***************************
           Table: city
    Create Table: CREATE TABLE `city` (
      `ID` int(11) NOT NULL AUTO_INCREMENT,
      `Name` char(35) NOT NULL DEFAULT '',
      `CountryCode` char(3) NOT NULL DEFAULT '',
      `District` char(20) NOT NULL DEFAULT '',
      `Population` int(11) NOT NULL DEFAULT '0',
      PRIMARY KEY (`ID`),
      KEY `CountryCode` (`CountryCode`),
      CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `country` (`Code`)
    ) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=latin1
    1 row in set (0.00 sec)

    4.

    mysql> start transaction;
    Query OK, 0 rows affected (0.00 sec)

    5.

    mysql> select * from city where name = 'manta';
    +-----+-------+-------------+----------+------------+
    | ID  | Name  | CountryCode | District | Population |
    +-----+-------+-------------+----------+------------+
    | 600 | Manta | ECU         | Manab铆   |     164739 |
    +-----+-------+-------------+----------+------------+
    1 row in set (0.01 sec)
    
    mysql> delete from city where name = 'manta';
    Query OK, 1 row affected (0.02 sec)
    
    mysql> select * from city where name = 'manta';
    Empty set (0.00 sec)
    
    mysql> rollback;
    Query OK, 0 rows affected (0.02 sec)
    
    mysql> select * from city where name = 'manta';
    +-----+-------+-------------+----------+------------+
    | ID  | Name  | CountryCode | District | Population |
    +-----+-------+-------------+----------+------------+
    | 600 | Manta | ECU         | Manab铆   |     164739 |
    +-----+-------+-------------+----------+------------+
    1 row in set (0.01 sec)
  • 相关阅读:
    codevs 1115 开心的金明
    POJ 1125 Stockbroker Grapevine
    POJ 2421 constructing roads
    codevs 1390 回文平方数 USACO
    codevs 1131 统计单词数 2011年NOIP全国联赛普及组
    codevs 1313 质因数分解
    洛谷 绕钉子的长绳子
    洛谷 P1276 校门外的树(增强版)
    codevs 2627 村村通
    codevs 1191 数轴染色
  • 原文地址:https://www.cnblogs.com/tomatoes-/p/6024445.html
Copyright © 2011-2022 走看看