New York State Driver's Template
virus is blocking transactions and MySQL tables By default, MySQL runs with autocommit mode
activated. This means that once you run a command that updates (modifies) a table, MySQL stores the update on disk.
This mode
autocommit can only be cleared if are working with InnoDB tables
(which are also the only ones to support referential integrity in MySQL).
SET AUTOCOMMIT = 0;
After disabling autocommit (set autocommit = 0;) obligations will be used obligatorily COMMIT to save or ROLLBACK to undo. To disable autocommit mode for a single series
command, you can use the command
START TRANSACTION
Example: create a new table in the database
Company: `CREATE TABLE` departamentos2 (
CODIGODEP `` INTEGER (11) NOT NULL DEFAULT '0 ', `NOMBREDEP
` VARCHAR (100), BUDGET
`` INTEGER (11) DEFAULT NULL,
PRIMARY KEY (`CODIGODEP `)
) ENGINE = InnoDB
and now will insert records departments table in a transaction departamentos2
START TRANSACTION;
SELECT @ A: = budget
FROM departments WHERE codigodep = 11 INSERT INTO
departamentos2 (codigodep, nombredep, budget )
VALUES (11, 'test', @ A);
COMMIT;
In the example above the budget of the department store in the variable 11
@ A
and then allocate the budget Table departamentos2 now an example where all data object any one department in the table
departamentos2
START TRANSACTION;
SELECT @ A: = budget, @ B: = codigodep, @ C: = nombredep
FROM departments WHERE codigodep = 33;
INSERT INTO departamentos2 (codigodep , nombredep, budget)
VALUES ( @ B, @ C, @ A
)
COMMIT;
In the preceding example copying an entire department to the departments table 2 ....
can add and allocate budgets as follows:
START TRANSACTION; SELECT @ A: = BUDGET FROM departments WHERE codigodep = 11;
departamentos2 UPDATE SET BUDGET = BUDGET + @ A WHERE codigodep = 33; COMMIT;
In this last example update the department's budget 33 of the table
departamentos2 adding the entire budget of the department table 11
departments
When you perform a SQL transaction to be taken into account that the table is locked
leaving only enabled to the one we are doing
0 comments:
Post a Comment