Skip to content

Instantly share code, notes, and snippets.

@MrCoffey
Last active August 27, 2015 02:04
Show Gist options
  • Save MrCoffey/1b9bccdb9c0aeda64ab2 to your computer and use it in GitHub Desktop.
Save MrCoffey/1b9bccdb9c0aeda64ab2 to your computer and use it in GitHub Desktop.
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
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