Sie sind auf Seite 1von 21

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,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema DBlab12_taller1
-- -----------------------------------------------------
-- base de datos de una escuela
-- -----------------------------------------------------
-- Schema DBlab12_taller1
-- base de datos de una escuela
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS DBlab12_taller1 DEFAULT CHARACTER SET utf8 ;
USE DBlab12_taller1 ;
-- -----------------------------------------------------
-- Table `DBlab12_taller1`.`TbProfesor`
-- -----------------------------------------------------

DROP TABLE IF EXISTS TbProfesor ;


CREATE TABLE IF NOT EXISTS TbProfesor (
Doc_prof VARCHAR(11) NOT NULL COMMENT 'Clave primaria del docente',
Nom_prof VARCHAR(30) NOT NULL,
ape_prof VARCHAR(30) NOT NULL,
cate_prof INT NOT NULL,
sal_prof INT NOT NULL,
PRIMARY KEY (Doc_prof))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DBlab12_taller1`.`TbCurso`
-- -----------------------------------------------------
DROP TABLE IF EXISTS TbCurso;

CREATE TABLE IF NOT EXISTS TbCurso (


Cod_curso VARCHAR(11) NOT NULL,
Nom_Curso VARCHAR(100) NOT NULL,
Horas_curso INT NOT NULL,
valor_curso INT NOT NULL,
PRIMARY KEY (cod_curso))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `DBlab12_taller1`.`TbEstudiante`
-- -----------------------------------------------------
DROP TABLE IF EXISTS TbEstudiante;

CREATE TABLE IF NOT EXISTS TbEstudiante (


Doc_est VARCHAR(11) NOT NULL,
nom_est varchar(30) not null,
Ape_Est VARCHAR(30) NOT NULL,
edad int not null,
PRIMARY KEY (Doc_est))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DBlab12_taller1`.`tbEstudiantexCurso`
-- -----------------------------------------------------
DROP TABLE IF EXISTS tbEstudiantexCurso ;

CREATE TABLE IF NOT EXISTS tbEstudiantexCurso


(
Cod_cur_estcur VARCHAR(11) NOT NULL,
doc_est_estcur VARCHAR(11) NOT NULL,
fecha_ini_estcur DATE NOT NULL,
FOREIGN KEY(Cod_cur_estcur) REFERENCES TbCurso(cod_curso),
FOREIGN KEY(doc_est_estcur) REFERENCES TbEstudiante(Doc_est)
ON DELETE CASCADE ON UPDATE CASCADE)
engine= innoDb;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
Script de creacin e insercin de datos

-- Autor: Manolo Pjaro Borrs

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,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS dblab12_taller2 DEFAULT CHARACTER SET utf8 ;
USE dblab12_taller2 ;

-- -----------------------------------------------------
-- Table `dblab12_taller2`.`tbArticulo`
-- -----------------------------------------------------
DROP TABLE IF EXISTS dblab12_taller2.tbArticulo ;

CREATE TABLE IF NOT EXISTS dblab12_taller2.tbArticulo (


Id_art INT NOT NULL AUTO_INCREMENT COMMENT 'Clave primaria',
Tit_art VARCHAR(100) NOT NULL,
Aut_art VARCHAR(100) NOT NULL,
Edi_art VARCHAR(300) NOT NULL,
prec_art INT NOT NULL,
PRIMARY KEY (Id_art))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `dblab12_taller2`.`tbcliente`
-- -----------------------------------------------------
DROP TABLE IF EXISTS dblab12_taller2.tbcliente ;

CREATE TABLE IF NOT EXISTS dblab12_taller2.tbcliente (


Id_cli VARCHAR(11) NOT NULL,
nom_cli VARCHAR(30) NOT NULL,
ape_cli VARCHAR(30) NOT NULL,
dir_cli VARCHAR(100) NOT NULL,
dep_cli VARCHAR(20) NOT NULL,
mes_cum_cli VARCHAR(10) NOT NULL,
PRIMARY KEY (Id_cli))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `dblab12_taller2`.`tbpedido`
-- -----------------------------------------------------
DROP TABLE IF EXISTS dblab12_taller2.tbpedido ;

CREATE TABLE IF NOT EXISTS dblab12_taller2.tbpedido (


Id_Ped INT NOT NULL AUTO_INCREMENT COMMENT 'Clave primaria',
Id_cli_ped VARCHAR(11) NOT NULL,
Fec_ped DATE NOT NULL,
Val_ped INT NULL,
PRIMARY KEY (Id_Ped),
FOREIGN KEY(Id_cli_ped) REFERENCES Tbcliente(Id_cli)
ON DELETE CASCADE ON UPDATE CASCADE)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `dblab12_taller2`.`tbArticuloxPedido`
-- -----------------------------------------------------
DROP TABLE IF EXISTS dblab12_taller2.tbArticuloxPedido;

CREATE TABLE IF NOT EXISTS dblab12_taller2.tbArticuloxPedido (


Id_ped_artped INT NOT NULL,
Id_art_artped INT NOT NULL,
Can_art_artped INT NOT NULL,
Val_ven_art_artped INT NOT NULL,
FOREIGN KEY(Id_ped_artped) REFERENCES Tbpedido(Id_ped),
FOREIGN KEY(Id_art_artped) REFERENCES tbarticulo(Id_art)
ON DELETE CASCADE ON UPDATE CASCADE)
engine = InnoDB;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

/* script que permite agregar registro a la base de datos de taller 2


clientes */

use DBlab12_taller2;
insert into tbcliente
(Id_cli,nom_cli,ape_cli,dir_cli,dep_cli,mes_cum_cli) values
('63502718','maritza','Rojas','calle 44 No 14-45','Santander','Abril'),
('13890234','Roger','Ariza','Cra 30 No 13-45','Antioquia','Junio'),
('77191956','Juan Carlos','Arenas','Diagonal 23 No 12-34 Apto
101','Valle','Marzo'),
('1098765789','Catalina','Zapata','Av el Libertador No 30-
14','Cauca','Marzo');

insert into tbarticulo(tit_art,aut_art,edi_art,prec_art) values


('Redes Cisco','ErnestoArigasello','AlfaMomega-Rama',60000),
('FaceBook y Twiter para Adultos','Veloso Claudio','AlfaMomega',52000),
('Creacion de un portall con Php y Mysql','Jacobo Pavn
Puertas','AlfaMomega-Rama',40000),
('administracion de sistemas operativos','Juiio Gmez Lpez','AlfaMomega-
Rama',55000);

Insert into tbpedido(Id_cli_ped,fec_ped,val_ped) values


('63502718','2012/02/25',120000),
('77191956','2012/04/30',55000),
('63502718','2011/12/10',260000),
('1098765789','2012/02/25',1800000);

insert into
tbArticuloxPedido(id_Ped_artped,id_art_artped,can_art_artped,val_ven_art_
artped) values
(1,3,5,40000),
(1,4,12,55000),
(2,1,5,65000),
(3,2,10,55000),
(3,3,12,45000),
(4,1,20,65000);
Consultas
-- MySQL Workbench Forward Engineering
-- Autor Aprendiz: Manolo Pjaro
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,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema DbLab12_taller3
-- -----------------------------------------------------

CREATE SCHEMA IF NOT EXISTS DbLab12_taller3 DEFAULT CHARACTER SET utf8 ;


USE DbLab12_taller3 ;

-- -----------------------------------------------------
-- Table `DbLab12_taller3`.`tbTiposAutomotores`
-- -----------------------------------------------------
DROP TABLE IF EXISTS DbLab12_taller3.tbTiposAutomotores ;

CREATE TABLE IF NOT EXISTS DbLab12_taller3.tbTiposAutomotores (


Autotipo INT NOT NULL COMMENT 'Tipo de autos',
AutoNombre VARCHAR(30) CHARACTER SET 'big5' COLLATE 'big5_bin' NOT NULL
COMMENT 'tabla Tipos de Automotores',
PRIMARY KEY (Autotipo))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DbLab12_taller3`.`TbAutomotores`
-- -----------------------------------------------------
DROP TABLE IF EXISTS DbLab12_taller3.TbAutomotores ;

CREATE TABLE IF NOT EXISTS DbLab12_taller3.TbAutomotores (


AutoPlaca VARCHAR(6) NOT NULL,
AutoMarca VARCHAR(30) NOT NULL,
AutoTipo INT NOT NULL,
AutoModelo INT NOT NULL,
AutoNumPasajeros INT NOT NULL COMMENT 'Tabla de Autos',
AutoCelindraje INT NOT NULL,
Autonumchasis VARCHAR(20) NOT NULL,
PRIMARY KEY (AutoPlaca),
FOREIGN KEY(autotipo) REFERENCES tbTiposAutomotores(Autotipo)
ON DELETE CASCADE ON UPDATE CASCADE)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DbLab12_taller3`.`Tbaseguramiento`
-- -----------------------------------------------------
DROP TABLE IF EXISTS DbLab12_taller3,Tbaseguramiento ;

CREATE TABLE IF NOT EXISTS DbLab12_taller3.Tbaseguramiento (


Asecodigo INT NOT NULL AUTO_INCREMENT,
AsefechaInicio DATE NOT NULL,
AsefechaExpiracion DATE NOT NULL,
AsevalorAsegurado INT NOT NULL,
Aseestado VARCHAR(30) NOT NULL,
AseCosto INT NOT NULL,
Aseplaca VARCHAR(6) NOT NULL COMMENT 'Contiene los tipos de
aseguramiento',
PRIMARY KEY (Asecodigo),
FOREIGN KEY(Aseplaca ) REFERENCES TbAutomotores(Autoplaca)
ON DELETE CASCADE ON UPDATE CASCADE)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DbLab12_taller3`.`Tbcompania`
-- -----------------------------------------------------
DROP TABLE IF EXISTS DbLab12_taller3.Tbcompania ;

CREATE TABLE IF NOT EXISTS DbLab12_taller3.Tbcompania


(
ComNit VARCHAR(11) NOT NULL,
ComNombre VARCHAR(30) NOT NULL,
ComaoFunc INT NOT NULL,
comRepLegal VARCHAR(100) NOT NULL COMMENT 'Datos de la empresa',
PRIMARY KEY (ComNit))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DbLab12_taller3`.`TbIncidente`
-- -----------------------------------------------------
DROP TABLE IF EXISTS DbLab12_taller3.TbIncidente ;

CREATE TABLE IF NOT EXISTS DbLab12_taller3.TbIncidente(


InciCodigo INT NOT NULL AUTO_INCREMENT,
InciFecha DATE NOT NULL,
InciPlaca VARCHAR(6) NOT NULL,
InciLugar VARCHAR(40) NOT NULL,
InciCantHeridos INT NOT NULL,
InciCanFatalidades INT NOT NULL,
InciCanAutosInvolucrados INT NOT NULL,
PRIMARY KEY (InciCodigo),
FOREIGN KEY(Inciplaca ) REFERENCES TbAutomotores(Autoplaca)
ON DELETE CASCADE ON UPDATE CASCADE)
ENGINE = InnoDB;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

-- --------------------- iNSERTAR DATOS --------------------------------

use DBlab12_taller3;
insert into tbcompania (ComNit,ComNombre,ComaoFunc,ComRepLegal ) values
('800890890-2','Seguros Atlantida',1998,'Carlos Lpez'),
('899999999-1','Aseguradora Rojas',1991,'Luis Fernando Rojas'),
('899999999-5','Seguros del Estadio',2001,'Maria Margarita Prez');

insert into tbtiposautomotores (autotipo, autonombre) values


(1,'Automoviles'),
(2,'Camperos'),
(3,'Camiones');

Insert into Tbautomotores


(AutoPlaca,Automarca,AutoTipo,AutoModelo,AutoNumPasajeros,AutoCelindraje,
Autonumchasis) values
('FLL420','Chevrolet corsa',1,2003,5,1400,'wywzzz167kk009d25'),
('DKZ820','renault stepway',1,2008,5,1600,'wywwzz157kk009d45'),
('KJQ920','kia sportage',2,2009,7,2000,'wywzzz157kk009d25');

insert into tbaseguramiento (AsefechaInicio, AsefechaExpiracion,


AsevalorAsegurado, Aseestado, AseCosto ,Aseplaca) values
('2012-09-30','2013-09-30',30000000,'Vigente',500000,'FLL420'),
('2012-09-27','2013-09-27',35000000,'Vigente',600000,'DKZ820'),
('2011-09-28','2012-09-28',50000000,'Vencido',800000,'KJQ920');

INSERT INTO tbincidente


(Incifecha,Inciplaca,inciLugar,InciCantHeridos,InciCanFatalidades,InciCan
AutosInvolucrados) values
('2012-09-30','DKZ820','Bucaramanga',0,0,2),
('2012-09-27','FLL420','Girn',1,0,1),
('2011-09-28','FLL420','Bucaramanga',1,0,2);
Consultas