Documente Academic
Documente Profesional
Documente Cultură
Digito mysql –u root –p enter pide password es enter esta secuencia me permite entrar a maria
db
Para crear una base de datos doy créate database laboratorioSQL; ENTER
Para ver las bases de datos creada digito show databases; enter
Para seleccionar la base de datos a trabajar damos el comando use laboratoriosql; enter
Después de seleccionar la base de datos vamos a crear la tabla profesor digitamos el comando
créate table profesor( enter
Describe estudiante
-> values(63502720,'martha','rojas',2,690000),
-> (91216904,'carlos','perez',3,950000),
-> (13826789,'maritza','angarita',1,550000),
-> (1098765789,'alejandra','torres',4,1100000);
Records:
4 Duplicates: 0 Warnings: 0
MariaDB [laboratoriosql]> insert into curso
-> values(63502720,'maria','perez',23),
-> (1098098097,'jonatan','ardila',17),
-> (1098765678,'carlos','martinez',19);
-> values(289011,1098765678,'01/02/2011'),
-> (250067,63502720,'01/03/2011'),
-> (289011,1098098097,'01/02/2011'),
-> (345671,63502720,'01/04/2011');
-> (250067,63502720,'2011-03-01'),
-> (289011,1098098097,'2011-02-01'),
-> (345671,63502720,'2011-04-01');
-> values
-> values
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to
your MariaDB server version for the right syntax to use near '' at line 1
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails
(`laboratoriosql`.`articuloxpedido`, CONSTRAINT `articuloxpedido_ibfk_2` FOREIGN KEY
(`id_art_artped`) REFERENCES `articulo` (`id_art`))
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails
(`laboratoriosql`.`articuloxpedido`, CONSTRAINT `articuloxpedido_ibfk_2` FOREIGN KEY
(`id_art_artped`) REFERENCES `articulo` (`id_art`))
MariaDB [laboratoriosql]> drop table articuloxpedido;
MariaDB [laboratoriosql]> create table Articulo( id_art int not null auto_increment, tit_art varchar
(100), aut_art varchar (100), edi_art varchar (300), prec_art int, primary key (id_art) );
MariaDB [laboratoriosql]> create table Pedido( id_ped int not null auto_increment, id_cli_ped
varchar(11), fec_ped Date, val_ped int, primary key(id_ped) );
MariaDB [laboratoriosql]> create table Pedido( id_ped int not null auto_increment, id_cli_ped
varchar(11), fec_ped Date, val_ped int, primary key(id_ped) );
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails
(`laboratoriosql`.`articuloxpedido`, CONSTRAINT `articuloxpedido_ibfk_1` FOREIGN KEY
(`id_ped_artped`) REFERENCES `pedido` (`id_ped`))
MariaDB [laboratoriosql]> insert into Articulo (tit_art, aut_art, edi_art, prec_art) values ('Redes
cisco','Ernesto Arigasello','Alfaomega-Rama',60000), ('Facebook y twitter para adultos','Velosa
Claudio','Alfaomega',52000), ('Creacion de un portal con php y mysql','Jacobo Pavon
Puertas','Alfaomega-Rama',40000), ('Administracion de sistemas operativos','Julio Gomez
Lopez','Alfaomega-Rama',55000);
+--------+---------------------------------------+----------------------+----------------+----------+
+--------+---------------------------------------+----------------------+----------------+----------+
+--------+---------------------------------------+----------------------+----------------+----------+
4 rows in set (0.00 sec)
MariaDB [laboratoriosql]> insert into Pedido (id_ped, id_cli_ped, fec_ped, val_ped) values
('',63502718,'2012-02-25',120000), ('',77191956,'2012-04-30',55000), ('',63502718,'2011-12-
10',260000), ('',1098765789,'2012-02-25',1800000);
+--------+------------+------------+---------+
+--------+------------+------------+---------+
+--------+------------+------------+---------+
-> values
(' at line 1
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to
your MariaDB server version for the right syntax to use near '' at line 1
+---------+---------+------+-----+---------+-------+
+---------+---------+------+-----+---------+-------+
+---------+---------+------+-----+---------+-------+
MariaDB [laboratoriosql]> alter table tiposautomotores add autonombre varchar(50) not null after
autotipo;
MariaDB [laboratoriosql]> alter table tiposautomotores add autonombre varchar(50) not null after
auttipo;
+------------+-------------+------+-----+---------+-------+
+------------+-------------+------+-----+---------+-------+
+------------+-------------+------+-----+---------+-------+
MariaDB [laboratoriosql]>
describe tiposautomotores;
+-----------+-------------+------+-----+---------+-------+
+-----------+-------------+------+-----+---------+-------+
+-----------+-------------+------+-----+---------+-------+
-> values
-> (1,'automoviles'),
-> (2,'camperos'),
-> (3,'camiones');
+---------+-------------+
| auttipo | autnombre |
+---------+-------------+
| 1 | automoviles |
| 2 | camperos |
| 3 | camiones |
MariaDB [laboratoriosql]>
-> values
-> ('fll420','checrolet corsa',1,2003,5,1400,'wxwzzz167kk009d25'),
+-----------+-----------------+----------+------------+------------------+----------------+-------------------+
+-----------+-----------------+----------+------------+------------------+----------------+-------------------+
+-----------+-----------------+----------+------------+------------------+----------------+-------------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> INSERT INTO Aseguramientos(asecodigo, Asefechainicio,
asefechaexpiracion, asevalorasegurado, Aseestado, Asecosto, Aseplaca)values('','2012-09-
30','2013-09-30',30000000,'Vigente',500000,'FLL420'),('','2012-09-27','2013-09-
27',35000000,'Vigente',600000,'DKZ820'),('','2011-09-28','2012-09-
28',50000000,'Vencido',800000,'KJQ920');
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> select sal_prof from profesor order by cate_prof;
+----------+
| sal_prof |
+----------+
| 550000 |
| 690000 |
| 950000 |
| 1100000 |
+----------+
MariaDB [laboratoriosql]>
+----------+------------------------+------------+------------+
+----------+------------------------+------------+------------+
+----------+------------------------+------------+------------+
+----------------+
| count(doc_est) |
+----------------+
| 2|
+----------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT nom_est, min(edad_est) FROM Estudiante;
+---------+---------------+
| nom_est | min(edad_est) |
+---------+---------------+
| maria | 17 |
+---------+---------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT AVG(valor_curs) FROM Curso WHERE horas_curs>40;
+-----------------+
| AVG(valor_curs) |
+-----------------+
| 1775000.0000 |
+-----------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT AVG(sal_prof) FROM Profesor WHERE cate_prof=1;
+---------------+
| AVG(sal_prof) |
+---------------+
| 550000.0000 |
+---------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> Select * from Curso order by `valor_curs` asc;
+----------+-------------------------------+------------+------------+
+----------+-------------------------------+------------+------------+
+----------+-------------------------------+------------+------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT nom_prof, min(sal_prof) FROM Profesor;
+-----------+---------------+
| nom_prof | min(sal_prof) |
+-----------+---------------+
| alejandra | 550000 |
+-----------+---------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT Estudiante.doc_est, Estudiante.nom_est,
Estudiantexcurso.fec_ini_estcur,Curso.nom_curs, Curso.horas_curs, Curso.valor_curs FROM
Estudiante,Estudiantexcurso,Curso WHERE Estudiantexcurso.fec_ini_estcur='2011-02-01';
+------------+-------------+----------------+-------------------------------+------------+------------+
+------------+-------------+----------------+-------------------------------+------------+------------+
+------------+-------------+----------------+-------------------------------+------------+------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT * FROM Profesor WHERE sal_prof>500000 and
sal_prof<700000;
+----------+----------+----------+-----------+----------+
+----------+----------+----------+-----------+----------+
+----------+----------+----------+-----------+----------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT Cliente.nom_cli, Cliente.ape_cli, Cliente.dir_cli FROM Cliente,
pedido WHERE Pedido.fec_ped='2012-02-25';
+-------------+---------+------------------------------+
+-------------+---------+------------------------------+
+-------------+---------+------------------------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT Pedido.id_ped, Articulo.tit_art,
Pedido.id_cli_ped,Pedido.fec_ped, Pedido.val_ped FROM Pedido, Articulo ORDER BY
Articulo.tit_art;
+--------+---------------------------------------+------------+------------+---------+
+--------+---------------------------------------+------------+------------+---------+
+--------+---------------------------------------+------------+------------+---------+
MariaDB [laboratoriosql]>
+-------------+---------+-------------+
+-------------+---------+-------------+
+-------------+---------+-------------+
+-------------+------------------------------+---------------------------------------+----------+
+-------------+------------------------------+---------------------------------------+----------+
| juan carlos | diagonal 23 N°12-34 apto 101 | Facebook y twitter para adultos | 52000 |
| juan carlos | diagonal 23 N°12-34 apto 101 | Administracion de sistemas operativos | 55000 |
+-------------+------------------------------+---------------------------------------+----------+
MariaDB [laboratoriosql]>
+---------------------+----------+------------+---------+
+---------------------+----------+------------+---------+
+---------------------+----------+------------+---------+
+----------------+
| COUNT(edi_art) |
+----------------+
| 4|
+----------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT Articulo.id_art, Articulo.tit_art, Articulo.prec_art,
Articuloxpedido.can_art_artped FROM Articulo, Articuloxpedido;
+--------+---------------------------------------+----------+----------------+
+--------+---------------------------------------+----------+----------------+
+--------+---------------------------------------+----------+----------------+
MariaDB [laboratoriosql]>
+------------+-------------+---------+------------------------------+-----------+-------------+
| id_cli | nom_cli | ape_cli | dir_cli | dep_cli | mes_cum_cli |
+------------+-------------+---------+------------------------------+-----------+-------------+
| 77191956 | juan carlos | arenas | diagonal 23 N°12-34 apto 101 | valle | marzo |
+------------+-------------+---------+------------------------------+-----------+-------------+
MariaDB [laboratoriosql]>
+--------+---------------------------------------+----------------------+----------------+----------+
+--------+---------------------------------------+----------------------+----------------+----------+
+--------+---------------------------------------+----------------------+----------------+----------+
MariaDB [laboratoriosql]>
+--------+-------------+------------------------------+--------+----------------+
+--------+-------------+------------------------------+--------+----------------+
+--------+-------------+------------------------------+--------+----------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT * FROM Compañia WHERE comañofun >='1991' and
comañofun<='1998';
+-------------+-------------------+-----------+---------------------+
+-------------+-------------------+-----------+---------------------+
| 800890890-2 | seguros atlantida | 1998 | carlos lopez |
+-------------+-------------------+-----------+---------------------+
MariaDB [laboratoriosql]>
+-----------+------------+-----------------+------------------+----------------+----------+----------+-------------------+
+-----------+------------+-----------------+------------------+----------------+----------+----------+-------------------+
+-----------+------------+-----------------+------------------+----------------+----------+----------+-------------------+
MariaDB [laboratoriosql]>
+-----------+----------------+-------------------+----------+
+-----------+----------------+-------------------+----------+
+-----------+----------------+-------------------+----------+
3 rows in set (0.00 sec)
MariaDB [laboratoriosql]>
+-----------+----------------+----------+-----------+-------------------+
+-----------+----------------+----------+-----------+-------------------+
+-----------+----------------+----------+-----------+-------------------+
MariaDB [laboratoriosql]>
+-----------+----------------+--------------------+-------------------+------------------------+-----------+----------+-------
---+
+-----------+----------------+--------------------+-------------------+------------------------+-----------+----------+-------
---+
MariaDB [laboratoriosql]>
+-------------------------------+-----------+-------------------+
+-------------------------------+-----------+-------------------+
| 1 | Vigente | 30000000 |
+-------------------------------+-----------+-------------------+
MariaDB [laboratoriosql]>
+------------+-------------+-----------------+--------------------+-------------------+
+------------+-------------+-----------------+--------------------+-------------------+
MariaDB [laboratoriosql]>
+-------------+--------------------+-----------+-----------------------+
+-------------+--------------------+-----------+-----------------------+
+-------------+--------------------+-----------+-----------------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT MAX(Aseguramientos.asevalorasegurado),
Aseguramientos.asecodigo,Aseguramientos.Asefechainicio, Aseguramientos.asefechaexpiracion,
Aseguramientos.asevalorasegurado, Aseguramientos.Aseestado, Aseguramientos.Asecosto,
Automotores.autoplaca,Automotores.automarca, Automotores.Autotipo,
Automotores.Automodelo,Automotores.Autonumpasajeros, Automotores.Autocilindraje,
Automotores.Autonumchasis FROM Aseguramientos, Automotores;
+---------------------------------------+-----------+----------------+--------------------+-------------------+-----------+---
-------+-----------+----------------+----------+------------+------------------+----------------+-------------------+
+---------------------------------------+-----------+----------------+--------------------+-------------------+-----------+---
-------+-----------+----------------+----------+------------+------------------+----------------+-------------------+
+---------------------------------------+-----------+----------------+--------------------+-------------------+-----------+---
-------+-----------+----------------+----------+------------+------------------+----------------+-------------------+
MariaDB [laboratoriosql]>
MariaDB [laboratoriosql]> SELECT Automotores.autoplaca, Automotores.automarca,
Automotores.autocilindraje,Aseguramientos.asefechainicio, Aseguramientos.asefechaexpiracion,
Aseguramientos.aseestado FROM Automotores, Aseguramientos WHERE
Automotores.autotipo=1;
+-----------+-----------------+----------------+----------------+--------------------+-----------+
+-----------+-----------------+----------------+----------------+--------------------+-----------+
+-----------+-----------------+----------------+----------------+--------------------+-----------+
MariaDB [laboratoriosql]>