Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Create table Productos(
- idProducto int(11) unsigned not null auto_increment primary key,
- Nombre varchar(50) not null,
- Precio double,
- Marca varchar(45) not null,
- Categoria varchar(30) not null,
- Stock int(6) not null,
- Disponible boolean default false
- );
- */
- -- drop table if exist
- -- create table Talles (talle ENUM('S','M','L','XL','XXL') NOT NULL DEFAULT 'L');
- -- alter: modifica una TABLA
- -- add agrega una columna
- -- DROP elimina una columna
- -- DELETE elimina un registro
- -- change modifica EL NOMBRE DE una columna y OPCIONALMENTE la longitud del tipo de dato
- -- MODIFY: MODIFICA EL TIPO DE DATO SOLAMENTE
- -- RENAME: renombra una tabla
- /* ALTER TABLE <nombre tabla> RENAME >otro nombre>
- RENAME TABLE <nombre tabla> TO <otro nombre>*/
- -- delete from cursosql -- > POSIBLE INYECCION SQL
- -- RENAME TABLE productos TO articulos;
- -- articulosidProductotallesTER TABLE articulos DROP primary key;
- # alter table talles add column idProducto int not null unique;
- # alter table talles drop primary key;
- # alter table talles add column idTalle int(2) not null primary key;
- # select * from talles;
- -- ----------------------
- -- alter table talles add constraint idProducto
- -- foreign key(idProducto) REFERENCES articulos(idProducto);
- -- -----------------------------
- # INSERCION DE DATOS
- # FORMA COMPLETA
- -- INSERT INTO articulos(Nombre,Precio,Marca,Categoria,Stock,disponible,comentarios)
- -- VALUES ("IPHONE 11", 789.56, "Apple", "Smartphone", 122, false, "Importado de EEUU");
- -- select * from articulos
- # FORMA SQL
- -- INSERT INTO articulos
- -- SET Nombre="Iphone 12", Precio=880, Marca="Apple", Categoria="Smartphone", Stock=1000,
- -- disponible= True, comentarios="Con cargador y auriculares";
- -- FORMA SIMPLIFICADA
- -- insert into articulos
- -- VALUES (3,"Iphone 10",1020.66,"Apple","Smartphone",777,false,"Sin cargador,auriculares extra");
- -- select * from articulos
- -- select count(*) from nacimientos
- -- OTROS FORMATOS DE BBDD: en Excel --> csv, formato "WEB": JSON (JavaScript Object Notation)
- -- select IdPedido, Cargo, Cargo * 1.21 as "Cargo con IVA" from pedidos_neptuno order by Cargo, IdPedido DESC
- /*
- alter table clientes
- modify COD_CLIENTE varchar(5) not null primary key,
- modify EMPRESA varchar(25) not null,
- modify DIRECCION varchar(25) not null,
- modify CIUDAD varchar(20) not null,
- modify TELEFONO int unsigned not null,
- modify RESPONSABLE varchar(20) not null;
- */
- -- Sentencias: SELECT: seleccionar, ordenar, agrupar y filtrar
- -- clausulas: FROM, WHERE, GROUP BY,HAVING, ORDER BY
- -- otras cláusulas limit
- -- select * from nacimientos order by talla desc limit 5
- -- select COD_PRODUCTO,SECCION,
- -- NOMBRE as "Nombre Producto",IMPORTADO,ORIGEN,DIA,MES,ANO
- -- from productos limit 5 offset 9;
- -- Operadores de comparacion: = < > <= >= <>
- /*
- select COD_PRODUCTO,nombre
- from productos
- where
- COD_PRODUCTO = 4
- OR COD_PRODUCTO = 8
- OR COD_PRODUCTO = 10;
- */
- -- select * from nacimientos where EDAD_MADRE < 13 OR EDAD_MADRE > 50
- -- 2 + 7 * 4 = 30 --> operadores aritmeticos
- -- (2 + 7) * 4 = 36
- -- operadores de comparacion: < > = .....
- -- operadores logicos; or and not
- -- Precedencia: aritmeticos, comparacion, logicos
- # ARROJAN EL MISMO RESULTADO
- -- a) select * from nacimientos where not (EDAD_MADRE < 13 OR EDAD_MADRE > 50);
- -- a) select * from nacimientos where EDAD_MADRE between 13 and 50
- -- b) select * from nacimientos where EDAD_MADRE < 14 OR EDAD_MADRE > 50; -- ....11,13,51,52,....
- -- b) select * from nacimientos where EDAD_MADRE NOT between 14 and 50
- -- c) select * from nacimientos where EDAD_MADRE = 13 or EDAD_MADRE = 16 or EDAD_MADRE = 18;
- -- c) select * from nacimientos where edad_madre in (13,16,18) order by EDAD_MADRE;
- -- OPERADORES LIKE/NOT LIKE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement