Está en la página 1de 6

Vamos al lado izquierdo donde estn los objetos le damos refresh y vemos nuestra

base de datos crditos creada:

Luego decimos que vamos a usar la base de datos crdito:

Despus de esto empezamos con la creacin de las tablas:

-- create database CREDITOS;


use CREDITOS;
-- CREAR TABLA MUNICIPIOS;
create table municipios (
cod_municipio INT NOT NULL AUTO_INCREMENT,
primary key (cod_municipio)
);

-- CREAR TABLA SUCURSALES;


create table sucursales (
cod_sucursal INT NOT NULL AUTO_INCREMENT,
cod_municipio INT NOT NULL,
primary key (cod_sucursal),
CONSTRAINT cod_municipio foreign key (cod_municipio)
REFERENCES municipios(cod_municipio)
);
-- CREAR TABLA EMPLEADOS;
create table empleados (
num_id_empleado INT NOT NULL AUTO_INCREMENT,
cod_sucursal INT NOT NULL,
primary key (num_id_empleado),
CONSTRAINT cod_sucursal foreign key (cod_sucursal)
REFERENCES sucursales (cod_sucursal)
);
-- CREAR TABLA CLIENTES;
create table clientes (
num_id_client INT NOT NULL AUTO_INCREMENT,
tipo_id_client VARCHAR (2) NOT NULL,
lugar_exp VARCHAR (10) NOT NULL,
primer_nom_client VARCHAR (30) NOT NULL,
segundo_nom_client VARCHAR (30) ,
primer_apell_client VARCHAR (30)NOT NULL,
segundo_apell_client VARCHAR (30) NOT NULL,
direcc_resid_client VARCHAR (30) NOT NULL,
telefono_resid_client INT NOT NULL,
municip_resid_client VARCHAR (20) NOT NULL,
cod_municipio INT NOT NULL,
primary key (num_id_client),
CONSTRAINT cod_municipio foreign key (cod_municipio)
REFERENCES municipios (cod_municipio)
);
-- CREAR TABLA CREDITOS;
create table creditos (
num_id_credit INT NOT NULL AUTO_INCREMENT,
fecha_credit DATE,
monto_solicitado INT NOT NULL,
numero_id_empleado INT NOT NULL,
codigo_sucursal INT NOT NULL,
numero_id_client INT NOT NULL,
primary key (num_id_credit),
constraint num_id_empleado foreign key (num_id_empleado) REFERENCES
empleados (num_id_empleado),

constraint cod_sucursal foreign key (cod_sucursal) REFERENCES


sucursales (cod_sucursal),
constraint num_id_client foreign key (num_id_client) REFERENCES
clientes (num_id_client)
);
-- CREAR TABLA REFERENCIAS;
create table referencias (
num_id_ref INT NOT NULL AUTO_INCREMENT,
tipo_id_ref VARCHAR (2),
nombre_ref VARCHAR (30),
apell_ref VARCHAR (30),
tel_ref INT NOT NULL,
numero_id_cred INT NOT NULL,
primary key (num_id_ref),
constraint num_id_credit foreign key (num_id_credit) REFERENCES
creditos (num_id_credit)
);
-- CREAR TABLA REFERENCIAS FAMILIARES;
create table ref_familiares (
parentesco VARCHAR (20),
numero_id_ref INT NOT NULL,
numero_id_cred INT NOT NULL,
constraint num_id_ref foreign key (num_id_ref) REFERENCES referencias
(num_id_ref),
constraint num_id_cred foreign key (num_id_cred) REFERENCES creditos
(num_id_cred)
);

-- CREAR TABLA REFERENCIAS PERONALES;


create table ref_personales (
numero_id_ref INT NOT NULL,
numero_id_cred INT NOT NULL,
constraint num_id_ref foreign key (num_id_ref) REFERENCES referencias
(num_id_ref),
constraint num_id_cred foreign key (num_id_cred) REFERENCES creditos
(num_id_cred)
);

Corremos y vemos que fueron creadas las tablas con xito

Refrescamos las bases de datos y vemos nuestra base crditos, creada con sus
respectivas tablas:

También podría gustarte