MYSQL transaction processing

practise
 Customer A buys a product online, the price is 500.00 yuan, and the payment is made by online bank transfer.
 If customer A 's bank card balance is 2,000.00 yuan, and he pays seller B 500.00 yuan for the purchase of goods , the initial seller B 's account amount is 10,000.00 yuan
 Create database shop and create table account and insert 2 pieces of data

CREATE DATABASE shop; #Create database
USE shop; #Use database
CREATE TABLE account(
 id INT(10) AUTO_INCREMENT PRIMARY KEY COMMENT 'Auto increment',
 NAME VARCHAR(20) NOT NULL,
 yue INT(30)

); #create table and declare columns


INSERT INTO account(id,NAME,yue) VALUES (1,'customer',5000);
INSERT INTO account(id,NAME,yue) VALUES (2,'seller',1000); #Add data to the column

SET AUTOCOMMIT = 0; #Close the automatic commit of mysql
START TRANSACTION; #Start a transaction
UPDATE account SET yue=4500 WHERE id=1; #Modify data
UPDATE account SET yue=1500 WHERE id=2; #Modify data
COMMIT; #Submit a transaction
SET AUTOCOMMIT = 1; #Restore mysql's automatic commit


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324636392&siteId=291194637