Last active
August 27, 2015 02:04
-
-
Save MrCoffey/1b9bccdb9c0aeda64ab2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS `mydb`.`galleta` ( | |
`id` INT NOT NULL COMMENT '', | |
`name` VARCHAR(45) NULL COMMENT '', | |
`price` VARCHAR(45) NULL COMMENT '', | |
PRIMARY KEY (`id`) COMMENT '') | |
ENGINE = InnoDB | |
CREATE TABLE IF NOT EXISTS `mydb`.`venta` ( | |
`id` INT NOT NULL COMMENT '', | |
`total` VARCHAR(45) NULL COMMENT '', | |
`codigo` VARCHAR(45) NULL COMMENT '', | |
`galleta_id` INT NOT NULL COMMENT '', | |
PRIMARY KEY (`id`) COMMENT '', | |
INDEX `fk_venta_galleta_idx` (`galleta_id` ASC) COMMENT '', | |
CONSTRAINT `fk_venta_galleta` | |
FOREIGN KEY (`galleta_id`) | |
REFERENCES `mydb`.`galleta` (`id`) | |
ON DELETE NO ACTION | |
ON UPDATE NO ACTION) | |
ENGINE = InnoDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table if exists galletas; | |
drop table if exists ventas; | |
create table galletas ( | |
codigo int not null auto_increment, | |
nombre varchar(250), | |
sabor varchar(250), | |
precio integer, | |
primary key (codigo) | |
); | |
create table ventas ( | |
codigo_galleta int, | |
fecha datetime, | |
total integer, | |
foreign key (codigo_galleta) references galletas(codigo) | |
); | |
insert into galletas(nombre, sabor,precio) values ("choquis","vainilla",10); | |
insert into galletas(nombre, sabor,precio) values ("varquillo","mantequilla",20); | |
insert into galletas(nombre, sabor,precio) values ("emperador","chocolate",30); | |
insert into galletas(nombre, sabor,precio) values ("crema de nueve","vainilla",10); | |
insert into ventas(codigo_galleta,total) values (1,10); | |
insert into ventas(codigo_galleta,total) values (2,11); | |
select * from ventas; | |
select * from galletas; | |
select * from galletas | |
join ventas | |
on galletas.codigo = ventas.codigo_galleta; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment