Anda di halaman 1dari 3

Luis Felipe Mrquez Briceo C.I. 15.031.097 Seccin B Bases de Datos. Prctica de Transacciones 1. Escoger la base de datos.

mysql> use bdc; Database changed mysql> 2. Escoger una tabla de su sistema. 3. Crear en la tabla original un campo llamado serial del tipo longtext. mysql> ALTER TABLE bdc_tramites ADD serial LONGTEXT NOT NULL ; Query OK, 24 rows affected (0.02 sec) Records: 24 Duplicates: 0 Warnings: 0 mysql> 4. Crear un duplicado de dicha tabla. mysql> create table copia_bdc_tramites select * from bdc_tramites; Query OK, 24 rows affected (0.02 sec) Records: 24 Duplicates: 0 Warnings: 0 mysql> mysql> describe copia_bdc_tramites; +----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+-------+ | codg_tram | int(11) | NO | | 0 | | | codg_per | int(11) | NO | | NULL | | | codg_tipo_tram | int(11) | NO | | NULL | | | fecha_sol_tram | date | NO | | NULL | | | codg_tram_est | int(3) | YES | | NULL | | | obs_tram | varchar(255) | YES | | NULL | | | serial | longtext | NO | | NULL | | +----------------+--------------+------+-----+---------+-------+ 7 rows in set (0.00 sec) mysql> 5, Insertar 20 datos en la tabla original y duplicar su insercin de datos en la tabla de copia (Deben coincidir los datos en ambas tablas, incluir la funcin rand() en el campo serial) mysql>Begin; INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031097', '1', '2011-02-08', '2', 'primera insersin', rand());

INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031098', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031099', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031100', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031101', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031102', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031103', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031104', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031105', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031106', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031107', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031108', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031109', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031110', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031111', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031112', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031113', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031114', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031115', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO bdc_tramites (codg_per ,codg_tipo_tram ,fecha_sol_tram ,codg_tram_est ,obs_tram , serial) VALUES ('15031116', '1', '2011-02-08', '2', 'primera insersin', rand()); INSERT INTO copia_bdc_tramites SELECT * FROM bdc_tramites; commit; 6, Modificar 8 registros en la tabla original y modificar su campo serial con un nuevo valor RAND. mysql> begin; update bdc_tramites set codg_tram_est=3, serial=rand() where codg_tram = 1; update bdc_tramites set codg_tram_est=3, serial=rand() where codg_tram = 2;

update bdc_tramites set codg_tram_est=3, serial=rand() where codg_tram = 3; update bdc_tramites set codg_tram_est=3, serial=rand() where codg_tram = 4; update bdc_tramites set codg_tram_est=3, serial=rand() where codg_tram = 5; update bdc_tramites set codg_tram_est=3, serial=rand() where codg_tram = 6; update bdc_tramites set codg_tram_est=3, serial=rand() where codg_tram = 7; update bdc_tramites set codg_tram_est=3, serial=rand() where codg_tram = 8; commit; 7, Realizar un update a la tabla copia donde los campos serial no sean iguales segn su Id, es decir, los valores de la tabla original deben ser iguales a los valores de la tabla copia. comparacion de la tabla durante el begin y en otra consola.Con rollback no efectua la insercion. Con commit si la efectua. update copia_bdc_tramites c join bdc_tramites t on c.codg_tram==t.codg_tram set c.codg_tram_est=t.codg_tram_est, c.codg_per=t.codg_per, c.codg_tipo_tram=t.codg_tipo_tram, c.fecha_sol_tram=t.fecha_sol_tram, c.obs_tram=t.obs_tram, c.serial=t.serial;

Anda mungkin juga menyukai