viernes, 30 de mayo de 2014

R.A.2.2

UNIDAD 2.2
VALOR 10%
DISEÑA FORMULARIOS Y REPORTES, EMPLEANDO LOS RECUERSOS QUE OFRECE EL SISTEMA GESTOR DE DATOS
A)   ELABORACION DE APLICACIONES CON VISTAS
DEFINICION DE VISTAS
CREACION DE VISTAS
ELIMINACION DE VISTAS
USO DE VISTAS
B)    ELABORACION DE FORMULARIOS Y REPORTES
CREACION DE FORMULARIOS Y REPORTES
SELECCION DE DATOS
FORMATO PARA LOS DATOS
ELIMINACION DE FORMULARIOS Y REPORTES
USO DE FORMULARIO

jueves, 29 de mayo de 2014

PRACTICA 11


PRACTICA REPASO VISTAS

Enter password: ***

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.0.51b-community-nt-log MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database notas;

Query OK, 1 row affected (0.00 sec)

mysql> use notas;

Database changed

mysql> create table alumnos(matricula int not null primary key,nombre varchar(30

),apellidos varchar(50),semestre varchar(20),modulo varchar(50),calif_1 int,cali

f_2 int,calif_3 int);

Query OK, 0 rows affected (0.08 sec)

mysql> insert into alumnos(matricula,nombre,apellidos,semestre,modulo,calif_1,ca

lif_2,calif_3) values (123,'edith','martinez hernandez','cuarto','cobd',8,9,10),

(456,'manuel','zavala contreras','cuarto','cobd',9,8,7),(678,'irving','gonzalez

mena','cuarto','cobd',7,6,5);

Query OK, 3 rows affected (0.02 sec)

Records: 3  Duplicates: 0  Warnings: 0

mysql> create view vista_alumnos as select matricula,nombre,apellidos,(calif_1+c

alif_2+calif_3)/3 as promedio from alumnos;

Query OK, 0 rows affected (0.03 sec)

 

mysql> show tables;

+-----------------+

| Tables_in_notas |

+-----------------+

| alumnos         |

| vista_alumnos   |

+-----------------+

2 rows in set (0.03 sec)

mysql> select * from vista_alumnos;

+-----------+--------+--------------------+----------+

| matricula | nombre | apellidos          | promedio |

+-----------+--------+--------------------+----------+

|       123 | edith  | martinez hernandez |   9.0000 |

|       456 | manuel | zavala contreras   |   8.0000 |

|       678 | irving | gonzalez mena      |   6.0000 |

+-----------+--------+--------------------+----------+

3 rows in set (0.00 sec)

mysql> insert into alumnos values(912,'fabian','mora sanchez','cuarto','cobd',10,9,8);

Query OK, 1 row affected (0.00 sec)

mysql> select * from alumnos;

+-----------+--------+--------------------+----------+--------+---------+---------+---------+

| matricula | nombre | apellidos          | semestre | modulo | calif_1 | calif_

2 | calif_3 |

+-----------+--------+--------------------+----------+--------+---------+---------+---------+

|       123 | edith  | martinez hernandez | cuarto   | cobd   |       8 |9 |      10 |

|       456 | manuel | zavala contreras   | cuarto   | cobd   |       9 |8 |       7 |

|       678 | irving | gonzalez mena      | cuarto   | cobd   |       7 |6 |       5 |

|       912 | fabian | mora sanchez       | cuarto   | cobd   |      10 |9 |       8 |

+-----------+--------+--------------------+----------+--------+---------+---------+---------+

4 rows in set (0.00 sec)

mysql> select * from vista_alumnos;

+-----------+--------+--------------------+----------+

| matricula | nombre | apellidos          | promedio |

+-----------+--------+--------------------+----------+

|       123 | edith  | martinez hernandez |   9.0000 |

|       456 | manuel | zavala contreras   |   8.0000 |

|       678 | irving | gonzalez mena      |   6.0000 |

|       912 | fabian | mora sanchez       |   9.0000 |

+-----------+--------+--------------------+----------+

4 rows in set (0.00 sec)

 

PRACTICA # 12

Enter password: ***

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.0.51b-community-nt-log MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database biblioteca;

Query OK, 1 row affected (0.02 sec)

mysql> use biblioteca;

Database changed

mysql> create table librosdeunaeditorial(titulo varchar(20) not null primary key,isbn int,editorial varchar(20),paginas int,ano_de_edicion int);

Query OK, 0 rows affected (0.04 sec)

mysql> insert into librosdeunaeditorial(titulo,isbn,editorial,paginas,ano_de_edicion) values ('la quinta ola',9788,'molino',528,1997),('generacio z',9706,'destino',280,1980),('girl heart boy',9727,'alfaguara',320,1999);

Query OK, 3 rows affected (0.00 sec)

Records: 3  Duplicates: 0  Warnings: 0

mysql> create view vista_librosdeunaeditorial as select titulo,isbn,paginas as informacion  from librosdeunaeditorial;

Query OK, 0 rows affected (0.02 sec)

mysql> show tables;

+----------------------------+

| Tables_in_biblioteca       |

+----------------------------+

| librosdeunaeditorial       |

| vista_librosdeunaeditorial |

+----------------------------+

2 rows in set (0.00 sec)

mysql> select * from vista_librosdeunaeditorial;

+----------------+------+-------------+

| titulo         | isbn | informacion |

+----------------+------+-------------+

| la quinta ola  | 9788 |         528 |

| generacio z    | 9706 |         280 |

| girl heart boy | 9727 |         320 |

+----------------+------+-------------+

3 rows in set (0.00 sec)

mysql> drop view vista_librosdeunaeditorial;

Query OK, 0 rows affected (0.00 sec)

mysql> show tables;

+----------------------+

| Tables_in_biblioteca |

+----------------------+

| librosdeunaeditorial |

+----------------------+

1 row in set (0.00 sec)

 

 

PRCATICA 10


mysql> create database biblioteca_trigger_ejemplo;

Query OK, 1 row affected (0.05 sec)

mysql> use biblioteca_trigger_ejemplo;

Database changed

mysql> create table autor(codigo int not null auto_increment primary key,nombre

varchar(30));

Query OK, 0 rows affected (0.07 sec)

mysql> describe autor;

+--------+-------------+------+-----+---------+----------------+

| Field  | Type        | Null | Key | Default | Extra          |

+--------+-------------+------+-----+---------+----------------+

| codigo | int(11)     | NO   | PRI | NULL    | auto_increment |

| nombre | varchar(30) | YES  |     | NULL    |                |

+--------+-------------+------+-----+---------+----------------+

2 rows in set (0.05 sec)

mysql> create table libros(codigo int not null auto_increment primary key,titulo

 varchar(30),ISBN varchar(30),editorial varchar(30),num_paginas int);

Query OK, 0 rows affected (0.05 sec)

mysql> describe libros;

+-------------+-------------+------+-----+---------+----------------+

| Field       | Type        | Null | Key | Default | Extra          |

+-------------+-------------+------+-----+---------+----------------+

| codigo      | int(11)     | NO   | PRI | NULL    | auto_increment |

| titulo      | varchar(30) | YES  |     | NULL    |                |

| ISBN        | varchar(30) | YES  |     | NULL    |                |

| editorial   | varchar(30) | YES  |     | NULL    |                |

| num_paginas | int(11)     | YES  |     | NULL    |                |

+-------------+-------------+------+-----+---------+----------------+

5 rows in set (0.01 sec)

mysql> create table usuarios(codigo int not null auto_increment primary key,nomb

re varchar(30),direccion varchar(50),telefono varchar(30),codigo_ejemplar int);

Query OK, 0 rows affected (0.10 sec)

mysql> describe usuarios;

+-----------------+-------------+------+-----+---------+----------------+

| Field           | Type        | Null | Key | Default | Extra          |

+-----------------+-------------+------+-----+---------+----------------+

| codigo          | int(11)     | NO   | PRI | NULL    | auto_increment |

| nombre          | varchar(30) | YES  |     | NULL    |                |

| direccion       | varchar(50) | YES  |     | NULL    |                |

| telefono        | varchar(30) | YES  |     | NULL    |                |

| codigo_ejemplar | int(11)     | YES  |     | NULL    |                |

+-----------------+-------------+------+-----+---------+----------------+

5 rows in set (0.01 sec)

mysql> create table ejemplares(codigo_ejemplar int not null auto_increment prima

ry key,localizacion varchar(30));

Query OK, 0 rows affected (0.06 sec)

mysql> describe ejemplares;

 

+-----------------+-------------+------+-----+---------+----------------+

| Field           | Type        | Null | Key | Default | Extra          |

+-----------------+-------------+------+-----+---------+----------------+

| codigo_ejemplar | int(11)     | NO   | PRI | NULL    | auto_increment |

| localizacion    | varchar(30) | YES  |     | NULL    |                |

+-----------------+-------------+------+-----+---------+----------------+

2 rows in set (0.01 sec)

mysql> insert into usuarios(nombre,direccion,telefono,codigo_ejemplar) values

    -> ('miguel','ave signos 23','56221234',3);

Query OK, 1 row affected (0.03 sec)

 

mysql> insert into usuarios(nombre,direccion,telefono,codigo_ejemplar)values('mi

guel','ave signos 23','53221234',3),('pedro','calle tulipanes','54321234',4),('a

manda','ave.constelacion','56432345',5);

Query OK, 3 rows affected (0.09 sec)

Records: 3  Duplicates: 0  Warnings: 0

mysql> select *from usuarios;

+--------+--------+------------------+----------+-----------------+

| codigo | nombre | direccion        | telefono | codigo_ejemplar |

+--------+--------+------------------+----------+-----------------+

|      1 | miguel | ave signos 23    | 53221234 |               3 |

|      2 | pedro  | calle tulipanes  | 54321234 |               4 |

|      3 | amanda | ave.constelacion | 56432345 |               5 |

+--------+--------+------------------+----------+-----------------+

3 rows in set (0.01 sec)

mysql> create table copia_usuario(codigo int not null auto_increment primary key

,nombre_ant varchar(30),direccion_anterior varchar(50),telefono_anterior varchar

(50),codigo_ejemplar_anterior int,nombre_nuevo varchar(30),direccion_nueva varch

ar(50),telefono_nuevo varchar(30),codigo_ejemplar_nuevo int,usuario varchar(40),

modificado datetime,codigo_usuario int (4));

Query OK, 0 rows affected (0.13 sec)

mysql> describe copia_usuario;

+--------------------------+-------------+------+-----+---------+----------------+

| Field                    | Type        | Null | Key | Default | Extra |

+--------------------------+-------------+------+-----+---------+----------------+

| codigo                   | int(11)     | NO   | PRI | NULL    | auto_increment |

| nombre_ant               | varchar(30) | YES  |     | NULL    | |

| direccion_anterior       | varchar(50) | YES  |     | NULL    | |

| telefono_anterior        | varchar(50) | YES  |     | NULL    | |

| codigo_ejemplar_anterior | int(11)     | YES  |     | NULL    | |

| nombre_nuevo             | varchar(30) | YES  |     | NULL    | |

| direccion_nueva          | varchar(50) | YES  |     | NULL    | |

| telefono_nuevo           | varchar(30) | YES  |     | NULL    | |

| codigo_ejemplar_nuevo    | int(11)     | YES  |     | NULL    | |

| usuario                  | varchar(40) | YES  |     | NULL     |

| modificado               | datetime    | YES  |     | NULL    | |

| codigo_usuario           | int(4)      | YES  |     | NULL    | |

+--------------------------+-------------+------+-----+---------+----------------+

12 rows in set (0.11 sec)

mysql> CREATE TRIGGER

    -> elimina_usuarios_ejemplares

    -> AFTER DELETE ON usuarios

    -> FOR EACH ROW

    -> BEGIN

    -> INSERT INTO copia_usuario(nombre_ant,direccion_anterior,telefono_anterior

,codigo_ejemplar_anterior,usuario,modificado,codigo_usuario)

    -> VALUES (OLD.nombre,OLD.direccion,OLD.telefono,OLD.codigo_ejemplar,CURRENT

_USER (),NOW(),OLD.codigo_usuario);

    -> END;

    -> //

+--------+--------+------------------+----------+-----------------+

| codigo | nombre | direccion        | telefono | codigo_ejemplar |

+--------+--------+------------------+----------+-----------------+

|      1 | miguel | ave signos 23    | 53221234 |               3 |

|      2 | pedro  | calle tulipanes  | 54321234 |               4 |

|      3 | amanda | ave.constelacion | 56432345 |               5 |

+--------+--------+------------------+----------+-----------------+

3 rows in set (0.32 sec)

mysql> delete from usuarios where

    -> codigo_ejemplar=4//

Query OK, 1 row affected (0.51 sec)

mysql> select *from usuarios //

+--------+--------+------------------+----------+-----------------+

| codigo | nombre | direccion        | telefono | codigo_ejemplar |

+--------+--------+------------------+----------+-----------------+

|      1 | miguel | ave signos 23    | 53221234 |               3 |

|      3 | amanda | ave.constelacion | 56432345 |               5 |

+--------+--------+------------------+----------+-----------------+

2 rows in set (0.00 sec)

 

PRCATICA 9


mysql> CREATE DATABASE pruebas_dispara;

Query OK, 1 row affected (0.07 sec)

mysql> USE pruebas_dispara;

Database changed

mysql> CREATE TABLE clientes(id_cliente int not null auto_increment,nombre varch

ar(100),seccion varchar(20),Accion varchar(10) default 'Insertado',PRIMARY KEY(i

d_cliente),KEY(nombre));

Query OK, 0 rows affected (0.31 sec)

mysql> DESCRIBE clientes;

+------------+--------------+------+-----+-----------+----------------+

| Field      | Type         | Null | Key | Default   | Extra          |

+------------+--------------+------+-----+-----------+----------------+

| id_cliente | int(11)      | NO   | PRI | NULL      | auto_increment |

| nombre     | varchar(100) | YES  | MUL | NULL      |                |

| seccion    | varchar(20)  | YES  |     | NULL      |                |

| Accion     | varchar(10)  | YES  |     | Insertado |                |

+------------+--------------+------+-----+-----------+----------------+

4 rows in set (0.11 sec)

mysql> INSERT INTO clientes (nombre,seccion) VALUES ('Miguel','informatica'),('R

osa','comida'),('Maria','ropa'),('Albert','informatica'),('Jordi','comida');

Query OK, 5 rows affected (0.11 sec)

Records: 5  Duplicates: 0  Warnings: 0

mysql> select * from clientes;

+------------+--------+-------------+-----------+

| id_cliente | nombre | seccion     | Accion    |

+------------+--------+-------------+-----------+

|          1 | Miguel | informatica | Insertado |

|          2 | Rosa   | comida      | Insertado |

|          3 | Maria  | ropa        | Insertado |

|          4 | Albert | informatica | Insertado |

|          5 | Jordi  | comida      | Insertado |

+------------+--------+-------------+-----------+

5 rows in set (0.00 sec)

mysql> CREATE TABLE auditoria_clientes(id int not null auto_increment,nombre_ant

erior varchar(100),seccion_anterior varchar(20),nombre_nuevo varchar(100),seccio

n_nueva varchar(20),usuario varchar(40),modificado datetime,proceso varchar(10),

Id_Cliente int(4),primary key(id));

Query OK, 0 rows affected (0.36 sec)

mysql> DESCRIBE auditoria_clientes;

+------------------+--------------+------+-----+---------+----------------+

| Field            | Type         | Null | Key | Default | Extra          |

+------------------+--------------+------+-----+---------+----------------+

| id               | int(11)      | NO   | PRI | NULL    | auto_increment |

| nombre_anterior  | varchar(100) | YES  |     | NULL    |                |

| seccion_anterior | varchar(20)  | YES  |     | NULL    |                |

| nombre_nuevo     | varchar(100) | YES  |     | NULL    |                |

| seccion_nueva    | varchar(20)  | YES  |     | NULL    |                |

| usuario          | varchar(40)  | YES  |     | NULL    |                |

| modificado       | datetime     | YES  |     | NULL    |                |

| proceso          | varchar(10)  | YES  |     | NULL    |                |

| Id_Cliente       | int(4)       | YES  |     | NULL    |                |

+------------------+--------------+------+-----+---------+----------------+

9 rows in set (0.06 sec)

mysql> DELIMITER //

mysql> CREATE TRIGGER Inserta_auditoria_clientes

    -> AFTER INSERT ON clientes

    -> FOR EACH ROW

    -> BEGIN

    -> INSERT INTO auditoria_clientes(nombre_nuevo, seccion_nueva, usuario, modi

ficado, proceso, Id_Cliente) VALUES (NEW.nombre, NEW.seccion, CURRENT_USER(), NO

W(), NEW.Accion, NEW.id_cliente);

    -> END;

    -> //

Query OK, 0 rows affected (0.19 sec)

mysql> CREATE TRIGGER Modifica_auditoria_clientes

    -> BEFORE UPDATE ON clientes

    -> FOR EACH ROW

    -> BEGIN

    -> INSERT INTO auditoria_clientes(nombre_anterior, seccion_anterior, nombre_

nuevo, seccion_nueva, usuario, modificado, Id_Cliente) VALUES (OLD.nombre, OLD.s

eccion, NEW.nombre, NEW.seccion, CURRENT_USER(), NOW(), NEW.id_cliente);

    -> END;

    -> //

Query OK, 0 rows affected (0.20 sec)

mysql> CREATE TRIGGER Elimina_auditoria_clientes

    -> AFTER DELETE ON clientes

    -> FOR EACH ROW

    -> BEGIN

    -> INSERT INTO auditoria_clientes(nombre_anterior, seccion_anterior, usuario

, modificado, Id_Cliente) VALUES (OLD.nombre, OLD.seccion, CURRENT_USER(), NOW()

, OLD.id_cliente);

    -> END;

    -> //

Query OK, 0 rows affected (0.01 sec)

mysql> DELIMITER;

    -> SHOW TRIGGERS;

    -> INSERT INTO CLIENTES(nombre,seccion) VALUES ('Edith Martinez','Informatica');

    -> select * from clientes;

    -> select * from auditoria_clientes;

    -> UPDATE CLIENTES SET NOMBRE='JORDI APOLINAR',SECCION='PRODUCTIVIDAD' WHERE ID_CLIENTE=5;

    -> select * from clientes;

    -> select * from auditoria_clientes;

    -> DELETE FROM CLIENTES WHERE NOMBRE='Edith Martinez';

    -> select * from clientes;

    -> select * from auditoria_clientes