Crear la base de datos: CREATE DATABASE prueba; Usar la base de datos: USE prueba; Crear la tabla cliente, producto y compra: CREATE TABLE cliente (id_cliente integer PRIMARY KEY NOT NULL, nombre varchar(30) NOT NULL, dir varchar(40), tel integer ); CREATE TABLE prod (id_com int PRIMARY KEY NOT NULL, tipo varchar(10)); CREATE TABLE compra (id_cliente integer, id_com integer, INDEX (id_cliente), FOREIGN KEY(id_cliente) REFERENCES cliente(id_cliente), INDEX (id_com), FOREIGN KEY (id_com) REFERENCES producto(id_com)); Modificar la tabla: ALTER TABLE cliente ADD fecha_nac date AFTER nombre; ALTER TABLE cliente ADD celular integer; Cambiar un nombre de una tabla: RENAME TABLE prod TO producto; Mostrar atributos de la tabla: DESCRIBE cliente; Insertar una tupla: insert into cliente values (10, "Benito Juarez", "1990-10-4","14 sur s/n", 2222222); Insertar desde un archivo: load data local infile "e://notas//basesdedatos//info.txt" into table cliente; Consulta simple: select * from cliente; Consulta con selección: select nombre, tel from cliente; Consulta con restricción: select * from cliente where id_cliente=10; Consulta join: select nombre, tipo from cliente join compra join producto where cliente.id_cliente=compra.id_cliente and compra.id_com=producto.id_com; Crear una vista: CREATE VIEW datos AS select nombre, tipo from cliente join compra join producto where cliente.id_cliente=compra.id_cliente and compra.id_com=producto.id_com; Contar elementos dentro de una tabla: select count(tipo) from datos; select count(tipo) as total from datos; Selecciona filas distintas: select distinct tipo from datos; Cuenta cuantos elementos hay dentro de un atributo: select tipo, count(*) as total from datos group by tipo; select nombre, count(nombre) as total from datos group by nombre; Ordena datos: select * from datos order by nombre desc; Muestra los datos con NULL: select * from cliente where fecha_nac is NULL; Obtiene la edad: select nombre, (year(curdate())-year(fecha_nac)) as edad from cliente where fecha_nac is not NULL; select nombre, (year(curdate())-year(fecha_nac)) as edad from cliente; Obtiene el menor: select min(tel) from cliente; Obtiene el mayor: select max(tel) from cliente; Obtiene el promedio: select avg(tel) from cliente; Obtiene los valores que están dentro del intervalo: select id_cliente, nombre from cliente where id_cliente between 11 and 14; Obtiene los valores que están fuera del intervalo: select id_cliente, nombre from cliente where id_cliente not between 11 and 14