COMANDO MySql
Pasos para ingresar a Mysql
Z:\>C:
C:\>
C:\>cd/xampp/mysql/bin
C:\xampp\mysql\bin>mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.4.21-MariaDB mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> Bye
Comando para crear una base de datos
- create database Biblioteca
Comando para usar una base de datos
- use database Biblioteca
Comando para crear tablas
create tabla nom tabla
(campo 1 tipo(tamaño)nulo o no primary key,
campoN tipo(tamaño)nulo o n );
Comando para visualizar la estructura de una tabla
- describe libro;
Comando para eliminar un primary key
- alter table libro drop primary key;
Comando para poner nuevamente primary key
NOTA : PARA CREARUN UNA TABLA RELACIONAL SE DEBE CREAR LAS TABLAS PRINCIPALES
Comando para crea tabla relacional
MariaDB [biblioteca]> create table libro_autor
-> (Idlibro varchar(10) not null,
-> Idautor varchar(5) not null,
-> foreign key(Idlibro) references libro(Idlibro) on delete cascade on update cascade,
-> foreign key(Idautor) references autor(Idautor) on delete cascade on update cascade);
Agregar campos a una tabla al final
- alter table nombretabla add nombre de campo tipo(tamaño) not null;
Agregar campo a la mitad de dos
- MariaDB [biblioteca]> alter table libro add area varchar(20) not null after titulo;
Agregar campo al inicio tabla
- alter table nombretabla add nombre de campo tipo(tamaño) not null first;
- EJEMPLO : alter table libro add serial varchar(15) not null first;
Agregar campo al inicio tabla
- alter table nombretabla drop serial
Cambiar nombre de un campo
- alter table nombretabla change titulo nombre varchar(50) not null;
Visualizar como esta creada una tabla
- show create table libro;
Cambiar nombre de una tabla
- alter table nombretabla rename to nuevonombre;
Eliminar tabla
CREACIÓN DE TABLAS, ELIMINAR, INSERTAR ETC
https://remingtonedu-my.sharepoint.com/personal/maria_osorio_1065_miremington_edu_co/_layouts/15/onedrive.aspx?id=%2Fpersonal%2Fmaria%5Fosorio%5F1065%5Fmiremington%5Fedu%5Fco%2FDocuments%2FBASE%20DE%20DATOS%2Fbiblioteca%20ejercicio%2Etxt&parent=%2Fpersonal%2Fmaria%5Fosorio%5F1065%5Fmiremington%5Fedu%5Fco%2FDocuments%2FBASE%20DE%20DATOS
GUARDAR COPIA DE SEGURIDAD
C:\xampp\mysql\bin>C:\xampp\mysql\bin>mysqldump -B -uroot -p Biblioteca >C:/xampp/Biblioteca.sql (.txt)
CONDICIONALES
select * from libro where idlibro='l01';
select * from libro where nropagina<160;
select descripcion, nropagina, precio from libro where precio>5000;
select * from libro where descripcion=' BD II';
select * from libro where nropagina >=100 and precio>=65000;
select * from libro where idlibro='L01' or idlibro='L02' or idlibro='L03';
select * from libro where idlibro>='L01' and idlibro <='L05';
select * from libro where idlibro in('L01','L02','L05');
select * from libro where idlibro between 'L01' and 'L06';
select distinct autor.nombre,autor.codautor, editorial.codedit, editorial.nombre from autor inner join liautedi on autor.codautor=liautedi.codautor inner join editorial on liautedi.codedit=editorial.codedit;
select autor.nombre, liautedi.idlibro from autor left join liautedi on autor.codautor=liautedi.codautor where liautedi.idlibro is null into outfile 'c:/xampp/librojoin.xls';
GUARDAMOS ARCHIVOS EN EXCEL
into
outfile 'c:/xampp/libroautorjoin.xls'