Microsoft Windows [Versión 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Reservados todos los derechos.
C:\Users\Administrador>cd c:/xampp/mysql/bin
c:\xampp\mysql\bin>mysql -u root
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
mysql> create database videoclub;
c:\xampp\mysql\bin>mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Query OK, 1 row affected (0.06 sec)
mysql> use videoclub
Database changed
mysql> create table peliculas (pelicula_id int unsigned auto_increment, titulo v
archar(30) not null, actor varchar(40) not null, duracion int unsigned not null,
primary key (pelicula_id));
Query OK, 0 rows affected (0.19 sec)
mysql> explain peliculas;
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| pelicula_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| titulo | varchar(30) | NO | | NULL | |
| actor | varchar(40) | NO | | NULL | |
| duracion | int(10) unsigned | NO | | NULL | |
+-------------+------------------+------+-----+---------+----------------+
4 rows in set (0.12 sec)
mysql> insert into peliculas (titulo, actor, duracion) values ('pulp fiction','J
hon Travolta',90);
Query OK, 1 row affected (0.06 sec)
mysql> insert into peliculas (titulo, actor, durecion) values ('mision imposible
', 'Tom Cruise', 120);
ERROR 1054 (42S22): Unknown column 'durecion' in 'field list'
mysql> insert into peliculas (titulo, actor, durecion) values ('mision imposible
', 'Tom Cruise', 120);
ERROR 1054 (42S22): Unknown column 'durecion' in 'field list'
mysql> insert into peliculas (titulo, actor, duracion) values ('mision imposible
', 'Tom Cruise', 120);
Query OK, 1 row affected (0.04 sec)
mysql> insert into peliculas (titulo, actor, duracion) values ('Harry Potter II'
, 'Daniel Ricfield', 150);
Query OK, 1 row affected (0.07 sec)
mysql> select * from peliculas;
+-------------+------------------+-----------------+----------+
| pelicula_id | titulo | actor | duracion |
+-------------+------------------+-----------------+----------+
| 1 | pulp fiction | Jhon Travolta | 90 |
| 2 | mision imposible | Tom Cruise | 120 |
| 3 | Harry Potter II | Daniel Ricfield | 150 |
+-------------+------------------+-----------------+----------+
3 rows in set (0.02 sec)
mysql> select * from peliculas where (actor like "%Tom%") or (actor like "%Danie
l%");
+-------------+------------------+-----------------+----------+
| pelicula_id | titulo | actor | duracion |
+-------------+------------------+-----------------+----------+
| 2 | mision imposible | Tom Cruise | 120 |
| 3 | Harry Potter II | Daniel Ricfield | 150 |
+-------------+------------------+-----------------+----------+
2 rows in set (0.12 sec)
mysql> select distinct actor from peliculas;
+-----------------+
| actor |
+-----------------+
| Jhon Travolta |
| Tom Cruise |
| Daniel Ricfield |
+-----------------+
3 rows in set (0.09 sec)
mysql> select from peliculas where (duracion>120);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'from
peliculas where (duracion>120)' at line 1
mysql> select * from peliculas where (duracion>120);
+-------------+-----------------+-----------------+----------+
| pelicula_id | titulo | actor | duracion |
+-------------+-----------------+-----------------+----------+
| 3 | Harry Potter II | Daniel Ricfield | 150 |
+-------------+-----------------+-----------------+----------+
1 row in set (0.02 sec)
mysql> update peliculas set duracion=125 where (titulo like 'Harry Potter II' an
d actor like 'Daniel Ricfield');
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from peliculas;
+-------------+------------------+-----------------+----------+
| pelicula_id | titulo | actor | duracion |
+-------------+------------------+-----------------+----------+
| 1 | pulp fiction | Jhon Travolta | 90 |
| 2 | mision imposible | Tom Cruise | 120 |
| 3 | Harry Potter II | Daniel Ricfield | 125 |
+-------------+------------------+-----------------+----------+
3 rows in set (0.00 sec)
mysql> insert into peliculas (titulo, actor, duracion) values ('la misma luna','
Eugenio Derbez', 100);
Query OK, 1 row affected (0.07 sec)
mysql> select * from peliculas;
+-------------+------------------+-----------------+----------+
| pelicula_id | titulo | actor | duracion |
+-------------+------------------+-----------------+----------+
| 1 | pulp fiction | Jhon Travolta | 90 |
| 2 | mision imposible | Tom Cruise | 120 |
| 3 | Harry Potter II | Daniel Ricfield | 125 |
| 4 | la misma luna | Eugenio Derbez | 100 |
+-------------+------------------+-----------------+----------+
4 rows in set (0.00 sec)
mysql> delete from peliculas where pelicula_id=1;
Query OK, 1 row affected (0.10 sec)
mysql> select * from peliculas;
+-------------+------------------+-----------------+----------+
| pelicula_id | titulo | actor | duracion |
+-------------+------------------+-----------------+----------+
| 2 | mision imposible | Tom Cruise | 120 |
| 3 | Harry Potter II | Daniel Ricfield | 125 |
| 4 | la misma luna | Eugenio Derbez | 100 |
+-------------+------------------+-----------------+----------+
3 rows in set (0.00 sec)
mysql> select titulo, duracion from peliculas order by duracion;
+------------------+----------+
| titulo | duracion |
+------------------+----------+
| la misma luna | 100 |
| mision imposible | 120 |
| Harry Potter II | 125 |
+------------------+----------+
3 rows in set (0.01 sec)
mysql> select titulo, duracion, from peliculas order by titulo;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'from
peliculas order by titulo' at line 1
mysql> select titulo, duracion from peliculas order by titulo;
+------------------+----------+
| titulo | duracion |
+------------------+----------+
| Harry Potter II | 125 |
| la misma luna | 100 |
| mision imposible | 120 |
+------------------+----------+
3 rows in set (0.00 sec)
mysql> select count (*) from peliculas;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '*) fr
om peliculas' at line 1
mysql> select count(*)from peliculas;
+----------+
| count(*) |
+----------+
| 3 |
+----------+
1 row in set (0.02 sec)
mysql> select titulo, count(*)from peliculas group by titulo;
+------------------+----------+
| titulo | count(*) |
+------------------+----------+
| Harry Potter II | 1 |
| la misma luna | 1 |
| mision imposible | 1 |
+------------------+----------+
3 rows in set (0.01 sec)
mysql> select * from peliculas where (duracion>115) and (duracion<145);
+-------------+------------------+-----------------+----------+
| pelicula_id | titulo | actor | duracion |
+-------------+------------------+-----------------+----------+
| 2 | mision imposible | Tom Cruise | 120 |
| 3 | Harry Potter II | Daniel Ricfield | 125 |
+-------------+------------------+-----------------+----------+
2 rows in set (0.00 sec)
mysql>
Ejercicio:
Escribe con código SQL las siguientes instrucciones en tu cuaderno:
Crea una base de datos la cual se nombrará UVM.
Entra en la base de datos que acabas de crear y en ella crea las siguientes tablas:
Alumno, con los campos:
No. de cuenta.
Nombre del alumno
Teléfono
Nivel
Carrera
Materia
Calificación
Promedio Final
Docente, con los campos:
Clave docente
Nombre del docente
Teléfono
Profesión
Grado
Materia
Cuatrimestre
Añade en cada tabla dos registros.
Mostrar:
Tablas recién creadas.
Contenido de las tablas.
Aquellos docentes que imparten clase en el segundo cuatrimestre.
A los alumnos de la carrera de Ingeniería.
Todas las tablas que contiene tu base de datos.
Todas las bases de datos de SQL.
Borra la tabla Docentes.
Borra la Base de datos de Videoclub.
En la tabla de alumnos agrega un campo llamado Porcentaje de Avance, y agrega la información de los estudiantes.
Cristian Ivan Ruiz 19:52
Hola profe ! No sé si me recuerde pero le estoy muy agradecido por todo; fue mi profesor en Conalep tlalpan 1 y en cuarto semestre conocí MySQL en sus clases y al egresar de la escuela eh tenido trabajo con SQL los últimos tres años