Codigos SQL para montar Banco
Autor: Everaldo | Publicado: 2012-03-28T19:51:00-03:00

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';CREATE SCHEMA IF NOT EXISTS `info1_everaldo` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;USE `info1_everaldo` ;-- ------------------------------------------------------- Table `info1_everaldo`.`cliente`-- -----------------------------------------------------CREATE&nbsp; TABLE IF NOT EXISTS `info1_everaldo`.`cliente` (&nbsp; `cod_cliente` VARCHAR(2) NOT NULL ,&nbsp; `nome_cliente` VARCHAR(45) NULL ,&nbsp; `rua` VARCHAR(45) NULL ,&nbsp; `cidade` VARCHAR(45) NULL ,&nbsp; PRIMARY KEY (`cod_cliente`) )ENGINE = InnoDB;-- ------------------------------------------------------- Table `info1_everaldo`.`agencia`-- -----------------------------------------------------CREATE&nbsp; TABLE IF NOT EXISTS `info1_everaldo`.`agencia` (&nbsp; `cod_agencia` VARCHAR(3) NOT NULL ,&nbsp; `nome_agencia` VARCHAR(45) NULL ,&nbsp; `gerente` VARCHAR(45) NULL ,&nbsp; `cidade` VARCHAR(45) NULL ,&nbsp; PRIMARY KEY (`cod_agencia`) )ENGINE = InnoDB;-- ------------------------------------------------------- Table `info1_everaldo`.`conta`-- -----------------------------------------------------CREATE&nbsp; TABLE IF NOT EXISTS `info1_everaldo`.`conta` (&nbsp; `num_conta` MEDIUMINT(9) NOT NULL ,&nbsp; `saldo` VARCHAR(45) NULL ,&nbsp; `cod_agencia` VARCHAR(3) NOT NULL ,&nbsp; `cliente_cod_cliente` VARCHAR(2) NOT NULL ,&nbsp; PRIMARY KEY (`num_conta`) ,&nbsp; INDEX `fk_conta_agencia1` (`cod_agencia` ASC) ,&nbsp; INDEX `fk_conta_cliente1` (`cliente_cod_cliente` ASC) ,&nbsp; CONSTRAINT `fk_conta_agencia1`&nbsp;&nbsp;&nbsp; FOREIGN KEY (`cod_agencia` )&nbsp;&nbsp;&nbsp; REFERENCES `info1_everaldo`.`agencia` (`cod_agencia` )&nbsp;&nbsp;&nbsp; ON DELETE NO ACTION&nbsp;&nbsp;&nbsp; ON UPDATE NO ACTION,&nbsp; CONSTRAINT `fk_conta_cliente1`&nbsp;&nbsp;&nbsp; FOREIGN KEY (`cliente_cod_cliente` )&nbsp;&nbsp;&nbsp; REFERENCES `info1_everaldo`.`cliente` (`cod_cliente` )&nbsp;&nbsp;&nbsp; ON DELETE NO ACTION&nbsp;&nbsp;&nbsp; ON UPDATE NO ACTION)ENGINE = InnoDB;-- ------------------------------------------------------- Table `info1_everaldo`.`emprestimo`-- -----------------------------------------------------CREATE&nbsp; TABLE IF NOT EXISTS `info1_everaldo`.`emprestimo` (&nbsp; `num_emprestimo` INT NOT NULL ,&nbsp; `valor` VARCHAR(45) NULL ,&nbsp; `cod_agencia` VARCHAR(3) NOT NULL ,&nbsp; `cod_cliente` VARCHAR(2) NOT NULL ,&nbsp; PRIMARY KEY (`num_emprestimo`) ,&nbsp; INDEX `fk_emprestimo_agencia` (`cod_agencia` ASC) ,&nbsp; INDEX `fk_emprestimo_cliente1` (`cod_cliente` ASC) ,&nbsp; CONSTRAINT `fk_emprestimo_agencia`&nbsp;&nbsp;&nbsp; FOREIGN KEY (`cod_agencia` )&nbsp;&nbsp;&nbsp; REFERENCES `info1_everaldo`.`agencia` (`cod_agencia` )&nbsp;&nbsp;&nbsp; ON DELETE NO ACTION&nbsp;&nbsp;&nbsp; ON UPDATE NO ACTION,&nbsp; CONSTRAINT `fk_emprestimo_cliente1`&nbsp;&nbsp;&nbsp; FOREIGN KEY (`cod_cliente` )&nbsp;&nbsp;&nbsp; REFERENCES `info1_everaldo`.`cliente` (`cod_cliente` )&nbsp;&nbsp;&nbsp; ON DELETE NO ACTION&nbsp;&nbsp;&nbsp; ON UPDATE NO ACTION)ENGINE = InnoDB;SET SQL_MODE=@OLD_SQL_MODE;SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;