miércoles, 29 de mayo de 2013

Base de datos dbclientes

Para la siguiente entrada explicaremos la base de datos con un vídeo  aquí abajo dejaremos la sintaxis por si queda alguna duda. 


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 dbclientes;
Query OK, 1 row affected (0.07 sec)

mysql> use dbclientes;
Database changed
mysql> create table tbclientes(codigo_cli int primary key,nombre_cli varchar(250),trabajo_cli varchar(250));
Query OK, 0 rows affected (0.16 sec)


mysql> describe tbclientes;

mysql> insert into tbclientes(codigo_cli,nombre_cli,trabajo_cli) values (1,'Edith Martinez Hernandez','inform
atica '),(2,'Juan Carmona Hernandez','Control de la contaminacion'),(3,'Fernanda Lopez Perez','Productividad'
);
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from tbclientes;

mysql> create table tbcopiaclientes(codigo_cop int primary key,nombre_cop varchar(50),trabajo_cop varchar(50)
,usuario_cop varchar(50),modificado_cop datetime);
Query OK, 0 rows affected (0.18 sec)

mysql> describe tbclientes;
mysql> delimiter //
mysql> create trigger nuevocliente after insert on tbclientes for each row
    -> begin
    -> insert into tbcopiaclientes(codigo_cop,nombre_cop,trabajo_cop,usuario_cop,modificado_cop) values(new.c
odigo_cli,new.nombre_cli,new.trabajo_cli,current_user(),now());
    -> end //
Query OK, 0 rows affected (0.27 sec)

mysql> show triggers;
    -> delimiter;
    -> end//
+--------------+--------+------------+-----------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------+--
------+---------+--------------------------------------------+----------------+
| Trigger      | Event  | Table      | Statement
                                                                                                          | T
iming | Created | sql_mode                                   | Definer        |
+--------------+--------+------------+-----------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------+--
------+---------+--------------------------------------------+----------------+
| nuevocliente | INSERT | tbclientes | begin
insert into tbcopiaclientes(codigo_cop,nombre_cop,trabajo_cop,usuario_cop,modificado_cop) values(new.codigo_c
li,new.nombre_cli,new.trabajo_cli,current_user(),now());
end | AFTER  | NULL    | NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | root@localhost |
+--------------+--------+------------+-----------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------+--
------+---------+--------------------------------------------+----------------+
1 row in set (0.12 sec)

mysql> insert into tbclientes() values(4,'Carlos Manuel Zavala','Informatica');
    -> end //
Query OK, 1 row affected (0.07 sec)

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL ser
ver version for the right syntax to use near 'end' at line 1
mysql> select * from tbclientes//
+------------+--------------------------+-----------------------------+
| codigo_cli | nombre_cli               | trabajo_cli                 |
+------------+--------------------------+-----------------------------+
|          1 | Edith Martinez Hernandez | informatica                 |
|          2 | Juan Carmona Hernandez   | Control de la contaminacion |
|          3 | Fernanda Lopez Perez     | Productividad               |
|          4 | Carlos Manuel Zavala     | Informatica                 |
+------------+--------------------------+-----------------------------+
4 rows in set (0.00 sec)

mysql> select * from tbcopiaclientes//
+------------+----------------------+-------------+----------------+---------------------+
| codigo_cop | nombre_cop           | trabajo_cop | usuario_cop    | modificado_cop      |
+------------+----------------------+-------------+----------------+---------------------+
|          4 | Carlos Manuel Zavala | Informatica | root@localhost | 2013-05-21 16:59:40 |
+------------+----------------------+-------------+----------------+---------------------+
1 row in set (0.00 sec)




No hay comentarios:

Publicar un comentario