mysqlはカラムとトランザクションを識別します

16423 ワード

  1 #   
  2 /*
  3        
  4   :          ,          
  5 
  6 
  7   8 1、           ?   ,      key
  9 2、           ?    !
 10 3、            
 11 4、        SET auto_increment_increment=3;    
 12  13 
 14 
 15 */
 16 
 17 # 、         
 18 
 19 
 20 DROP TABLE IF EXISTS tab_identity;
 21 CREATE TABLE tab_identity(
 22     id INT  ,
 23     NAME FLOAT UNIQUE AUTO_INCREMENT,
 24     seat INT 
 25 
 26 
 27 );
 28 TRUNCATE TABLE tab_identity;
 29 
 30 
 31 INSERT INTO tab_identity(id,NAME) VALUES(NULL,'john');
 32 INSERT INTO tab_identity(NAME) VALUES('lucy');
 33 SELECT * FROM tab_identity;
 34 
 35 
 36 SHOW VARIABLES LIKE '%auto_increment%';
 37 
 38 
 39 SET auto_increment_increment=3;
 40 
 41 
 42 
 43 #TCL
 44 /*
 45 Transaction Control Language       
 46 
 47  48      sql          ,            ,       。
 49 
 50      
 51 
 52      1000
 53       1000
 54 
 55 update   set       =500 where name='   '
 56   
 57 update   set      =1500 where name='  '
 58 
 59 
 60  61 ACID
 62    :         ,           
 63  64  65    :        ,             .
 66 
 67 
 68 
 69      
 70  71   insert、update、delete  
 72 
 73 delete from   where id =1;
 74 
 75  76  77 
 78 set autocommit=0;
 79 
 80   1:    
 81 set autocommit=0;
 82 start transaction;   
 83   2:      sql  (select insert update delete)
 84   1;
 85   2;
 86 ...
 87 
 88   3:    
 89 commit;    
 90 rollback;    
 91 
 92 savepoint    ;     
 93 
 94 
 95 
 96  97                                
 98 read uncommitted:√        √        √
 99 read committed:  ×        √        √
100 repeatable read: ×        ×        √
101 serializable      ×             ×               ×
102 
103 
104 mysql            repeatable read
105 oracle           read committed
106       
107 select @@tx_isolation;
108       
109 set session|global transaction isolation level     ;
110 
111 
112 
113 
114        ;
115 update   set       =500 where name='   '
116 
117 update   set      =1500 where name='  ' 
118        ;
119 
120 
121 
122 */
123 
124 SHOW VARIABLES LIKE 'autocommit';
125 SHOW ENGINES;
126 
127 #1.         
128 
129 #    
130 SET autocommit=0;
131 START TRANSACTION;
132 #         
133 UPDATE account SET balance = 1000 WHERE username='   ';
134 UPDATE account SET balance = 1000 WHERE username='  ';
135 
136 #    
137 ROLLBACK;
138 #commit;
139 
140 SELECT * FROM account;
141 
142 
143 #2.      delete truncate      
144 
145 SET autocommit=0;
146 START TRANSACTION;
147 
148 DELETE FROM account;
149 ROLLBACK;
150 
151 
152 
153 #3.  savepoint    
154 SET autocommit=0;
155 START TRANSACTION;
156 DELETE FROM account WHERE id=25;
157 SAVEPOINT a;#     
158 DELETE FROM account WHERE id=28;
159 ROLLBACK TO a;#      
160 
161 
162 SELECT * FROM account;