Está en la página 1de 4

create database payedb

use payedb

create table Profesor(

dni char(8) not null primary key,


nombre varchar(50) not null,
paterno varchar(50) not null,
materno varchar(50) not null,
edad int not null,
especialidad varchar(50) not null,
porcentaje decimal not null

create table Proyecto(

id_proyecto int(11) not null primary key auto_increment,


fecha_inicio date not null,
fecha_fin date not null,
patrocinador varchar(50) not null,
num_proyecto char(5) not null,
presupuesto float not null
)

create table Alumno(

id_alumno int(11) not null primary key auto_increment,


dni char(8) not null,
nombre varchar(50) not null,
paterno varchar(50) not null,
materno varchar(50) not null,
edad int not null
)

create table Departamento(

id_departamento int(11) not null primary key auto_increment,


nombre_dep varchar(50) not null,
despacho_principal varchar(50) not null,
num_dep char(5) not null
)

create table Rango(

id_rango int(11) not null primary key auto_increment,


nombre_rango varchar(50) not null,
descripcion varchar(50) not null
)

create table Cat_prof(

id_cat int(11) not null primary key auto_increment,


nombre_cat varchar(50) not null,
descripcion_cat varchar(50) not null
)
create table Cat_alum(

id_cat_alum int(11) not null primary key auto_increment,


nombre_cat_alum varchar(50) not null,
descripcion_cat_alum varchar(50) not null
)

CREATE TABLE Programa_pos(

id_programa INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,


nombre_programa VARCHAR(50) NOT NULL,
descripcion_programa VARCHAR(50) NOT NULL
)

///////////////////////////
alter table profesor
add

id_cat int not null

alter table profesor


add

constraint cat_FK
foreign key (id_cat)
references Cat_prof(id_cat)
//////////////////////////
alter table profesor
add

id_rango int not null

alter table profesor


add

constraint rango_FK
foreign key (id_rango)
references Rango(id_rango)
///////////////////////////
alter table alumno
add

id_cat_alum int not null

alter table alumno


add

constraint cat_alum_FK
foreign key (id_cat_alum)
references Cat_alum(id_cat_alum)
///////////////////////////
alter table alumno
add

id_departamento int not null


alter table alumno
add

constraint departamento_FK
foreign key (id_departamento)
references departamento(id_departamento)

///////////////////////////
alter table alumno
add

constraint alumno_FK
foreign key (id_alumno)
references alumno(id_alumno)
///////////////////////////
alter table alumno
add

id_programa int not null

alter table alumno


add

constraint programa_FK
foreign key (id_programa)
references Programa_pos(id_programa)
//////////////////////////////////

CREATE TABLE PROFE_proyec(

DNI INT(11) NOT NULL ,


id_proyecto INT(11) NOT NULL,
)
//////////////////////////////
alter table PROFE_proyec
add

constraint DNI_FK
foreign key (DIN)
references profesor(DNI)

////////////////////////////
alter table PROFE_proyec
add

constraint proyecto_FK
foreign key (id_proyecto)
references proyecto(id_proyecto)
////////////////////////////

CREATE TABLE ALUM_proyec(


id_proyecto INT(11) NOT NULL,
id_alumno INT(11) NOT NULL

)
//////////////////////////////
alter table ALUM_proyec
add

constraint alumproyec_FK
foreign key (id_proyecto)
references proyecto(id_proyecto)

//////////////////////////////
alter table ALUM_proyec
add

constraint alumproyec1_FK
foreign key (id_alumno)
references proyecto(id_alumno)

/////////////////////////////
CREATE TABLE PROF_dep(
DNI INT(11) NOT NULL,
id_departamento INT(11) NOT NULL

)
//////////////////////////////
alter table PROF_dep
add

constraint profedep_FK
foreign key (DNI)
references profesor(DNI)

//////////////////////////////
alter table PROF_dep
add

constraint profedep1_FK
foreign key (id_departamento)
references departamento(id_departamento)

También podría gustarte