Contenido histórico

caosSQL

Este artículo pertenece al archivo histórico. Verifica fechas, convocatorias y enlaces antes de tomar una decisión.

CREATE TABLE escuela (
	esc_escuelaid integer NOT NULL, 
	esc_escuela varchar(100) NOT NULL, 
	esc_nombrecorto varchar(20), 
	esc_director varchar(100), 
	esc_url varchar(100), 
	esc_urlescudo varchar(100), 
	esc_aniversario date, 
	esc_fecharegistro timestamp DEFAULT 'now', 
	esc_estatus integer DEFAULT 1, 
	esc_direccion varchar(300), 
	esc_codigopostal varchar(5), 
	pai_paisid integer, 
	niv_nivelescolarid integer NOT NULL, 
	PRIMARY KEY(esc_escuelaid),
	FOREIGN KEY(niv_nivelescolarid) REFERENCES nivel_escolar (niv_nivelescolarid),
	FOREIGN KEY(pai_paisid) REFERENCES pais (pai_paisid));

CREATE TABLE colegio (
	col_colegioid integer NOT NULL, 
	col_colegio varchar(50), 
	PRIMARY KEY(col_colegioid));

CREATE TABLE nivel_escolar (
	niv_nivelescolarid integer NOT NULL, 
	niv_nivelescolar varchar(50), 
	PRIMARY KEY(niv_nivelescolarid));

CREATE TABLE colegios_escuela (
	esc_escuelaid integer NOT NULL, 
	col_colegioid integer NOT NULL, 
	PRIMARY KEY(esc_escuelaid, col_colegioid),
	FOREIGN KEY(esc_escuelaid) REFERENCES escuela (esc_escuelaid),
	FOREIGN KEY(col_colegioid) REFERENCES colegio (col_colegioid));

CREATE TABLE pais (
	pai_paisid integer NOT NULL, 
	pai_pais varchar(100), 
	pai_corto varchar(2), 
	PRIMARY KEY(pai_paisid));

CREATE TABLE asignatura (
	asi_asignaturaid integer NOT NULL, 
	asi_asignatura varchar(100) NOT NULL, 
	asi_creditos integer, 
	asi_grado integer, 
	asi_clave varchar(15), 
	asi_categoria varchar(20) DEFAULT 'OBLIGATORIA' CHECK(asi_categoria in ('OBLIGATORIA','OPTATIVA')), 
	asi_caracter integer CHECK(asi_caracter in (1,2,3,4,5)), 
	col_colegioid integer NOT NULL, 
	PRIMARY KEY(asi_asignaturaid),
	FOREIGN KEY(col_colegioid) REFERENCES colegio (col_colegioid));

CREATE TABLE pregunta (
	pre_preguntaid integer NOT NULL, 
	pre_pregunta varchar(300), 
	pre_exposicion integer DEFAULT 0, 
	pre_aciertos integer DEFAULT 0, 
	pre_nivel integer DEFAULT 0, 
	pre_publica integer DEFAULT 0 NOT NULL CHECK(pre_publica in (0,1)), 
	tip_tipopreguntaid integer, 
	con_contenidoid integer NOT NULL, 
	uni_unidadid integer NOT NULL, 
	prog_programaid integer NOT NULL, 
	usr_usuarioid integer NOT NULL, 
	PRIMARY KEY(pre_preguntaid),
	FOREIGN KEY(usr_usuarioid) REFERENCES usuario (usr_usuarioid),
	FOREIGN KEY(tip_tipopreguntaid) REFERENCES tipo_pregunta (tip_tipopreguntaid),
	FOREIGN KEY(con_contenidoid, uni_unidadid, prog_programaid) REFERENCES contenido (con_contenidoid, uni_unidadid, prog_programaid));

CREATE TABLE respuesta (
	res_respuestaid integer NOT NULL, 
	res_respuesta varchar(300), 
	res_exposicion integer DEFAULT 0, 
	con_contenidoid integer NOT NULL, 
	uni_unidadid integer NOT NULL, 
	prog_programaid integer NOT NULL, 
	usr_usuarioid integer NOT NULL, 
	PRIMARY KEY(res_respuestaid),
	FOREIGN KEY(con_contenidoid, uni_unidadid, prog_programaid) REFERENCES contenido (con_contenidoid, uni_unidadid, prog_programaid),
	FOREIGN KEY(usr_usuarioid) REFERENCES usuario (usr_usuarioid));

CREATE TABLE pregunta_respuesta (
	pre_preguntaid integer NOT NULL, 
	res_respuestaid integer NOT NULL, 
	pres_correcta integer DEFAULT 0, 
	pres_diagnostico varchar(500), 
	PRIMARY KEY(pre_preguntaid, res_respuestaid),
	FOREIGN KEY(pre_preguntaid) REFERENCES pregunta (pre_preguntaid),
	FOREIGN KEY(res_respuestaid) REFERENCES respuesta (res_respuestaid));

CREATE TABLE programa_estudio (
	prog_programaid integer NOT NULL, 
	prog_programa varchar(20), 
	prog_fechainicio date, 
	prog_horas integer, 
	prog_fecharegistro timestamp DEFAULT 'now', 
	asi_asignaturaid integer, 
	PRIMARY KEY(prog_programaid),
	FOREIGN KEY(asi_asignaturaid) REFERENCES asignatura (asi_asignaturaid));

CREATE TABLE unidad (
	uni_unidadid integer NOT NULL, 
	prog_programaid integer NOT NULL, 
	uni_unidad varchar(50), 
	uni_objetivo varchar(300), 
	uni_sesiones integer, 
	PRIMARY KEY(uni_unidadid, prog_programaid),
	FOREIGN KEY(prog_programaid) REFERENCES programa_estudio (prog_programaid));

CREATE TABLE contenido (
	con_contenidoid integer NOT NULL, 
	uni_unidadid integer NOT NULL, 
	prog_programaid integer NOT NULL, 
	con_contenido varchar(100), 
	con_contenidourl varchar(100), 
	con_descripcion varchar(1000), 
	PRIMARY KEY(con_contenidoid, uni_unidadid, prog_programaid),
	FOREIGN KEY(uni_unidadid, prog_programaid) REFERENCES unidad (uni_unidadid, prog_programaid));

CREATE TABLE usuario (
	usr_usuarioid integer NOT NULL, 
	usr_usuario varchar(20), 
	usr_contrasena varchar(20), 
	usr_matricula varchar(20), 
	usr_apellidopaterno varchar(50), 
	usr_apellidomaterno varchar(50), 
	usr_nombre varchar(50), 
	usr_correoelectronico varchar(50), 
	usr_fechanacimiento date, 
	usr_curp varchar(20), 
	usr_fecharegistro timestamp DEFAULT 'now', 
	usr_estatus integer DEFAULT 0 CHECK(usr_estatus in (-1,0,1)), 
	usr_telefonoCasa varchar(20), 
	usr_telefonoMovil varchar(20), 
	usr_imagenurl varchar(100), 
	usr_acercademi varchar(500), 
	usr_sitioweb varchar(500), 
	usr_mensajero varchar(500), 
	tusr_tipousuarioid integer NOT NULL, 
	PRIMARY KEY(usr_usuarioid),
	FOREIGN KEY(tusr_tipousuarioid) REFERENCES tipo_usuario (tusr_tipousuarioid));

CREATE TABLE tipo_usuario (
	tusr_tipousuarioid integer NOT NULL, 
	tusr_tipousuario varchar(20), 
	PRIMARY KEY(tusr_tipousuarioid));

CREATE TABLE tipo_pregunta (
	tip_tipopreguntaid  NOT NULL, 
	tip_tipopregunta varchar(20), 
	PRIMARY KEY(tip_tipopreguntaid));

CREATE TABLE grupo_usuario (
	grp_grupoid integer NOT NULL, 
	usr_usuarioid  NOT NULL, 
	grpu_tipomiembro integer NOT NULL, 
	grpu_calificacion integer, 
	PRIMARY KEY(grp_grupoid, usr_usuarioid),
	FOREIGN KEY(usr_usuarioid) REFERENCES usuario (usr_usuarioid));

CREATE TABLE grupo (
	grp_grupoid integer NOT NULL, 
	asi_asignaturaid integer NOT NULL, 
	grp_grupo varchar(50), 
	grp_fechainicio date, 
	grp_fechafin date, 
	grp_fecharegistro date, 
	PRIMARY KEY(grp_grupoid),
	FOREIGN KEY(asi_asignaturaid) REFERENCES asignatura (asi_asignaturaid),
	FOREIGN KEY(grp_grupoid) REFERENCES grupo_usuario (grp_grupoid));

CREATE TABLE elemento_calificacion (
	ecal_elementoid integer NOT NULL, 
	ecal_elemento varchar(20) NOT NULL, 
	ecal_descripcion varchar(200), 
	ecal_escala integer DEFAULT 10, 
	ecal_peso integer DEFAULT 1, 
	ecal_fecharegistro timestamp DEFAULT 'now', 
	teca_tipoelementoid integer NOT NULL, 
	usr_usuarioid integer NOT NULL, 
	PRIMARY KEY(ecal_elementoid),
	FOREIGN KEY(teca_tipoelementoid) REFERENCES tipo_elemento_cal (teca_tipoelementoid),
	FOREIGN KEY(usr_usuarioid) REFERENCES usuario (usr_usuarioid));

CREATE TABLE tipo_elemento_cal (
	teca_tipoelementoid integer NOT NULL, 
	teca_tipoelemento varchar(30) NOT NULL, 
	PRIMARY KEY(teca_tipoelementoid));

CREATE TABLE grupo_usr_elem_cal (
	grp_grupoid integer NOT NULL, 
	usr_usuarioid integer NOT NULL, 
	ecal_elementoid integer NOT NULL, 
	guec_calificacion float DEFAULT 0 NOT NULL, 
	PRIMARY KEY(grp_grupoid, usr_usuarioid, ecal_elementoid),
	FOREIGN KEY(ecal_elementoid) REFERENCES elemento_calificacion (ecal_elementoid),
	FOREIGN KEY(grp_grupoid, usr_usuarioid) REFERENCES grupo_usuario (grp_grupoid, usr_usuarioid));

CREATE TABLE pregunta_usuario (
	pre_preguntaid integer NOT NULL, 
	usr_usuarioid integer NOT NULL, 
	preu_valida integer DEFAULT 0 CHECK(preu_valida in (-1,0,1)), 
	PRIMARY KEY(pre_preguntaid, usr_usuarioid),
	FOREIGN KEY(pre_preguntaid) REFERENCES pregunta (pre_preguntaid),
	FOREIGN KEY(usr_usuarioid) REFERENCES usuario (usr_usuarioid));

CREATE TABLE comentario_pregunta (
	pre_preguntaid integer NOT NULL, 
	cop_fechahora timestamp DEFAULT 'now' NOT NULL, 
	cop_comentario varchar(500), 
	usr_usuarioid integer NOT NULL, 
	PRIMARY KEY(pre_preguntaid, cop_fechahora),
	FOREIGN KEY(usr_usuarioid) REFERENCES usuario (usr_usuarioid),
	FOREIGN KEY(pre_preguntaid) REFERENCES pregunta (pre_preguntaid));

CREATE TABLE examen (
	exa_examenid integer NOT NULL, 
	exa_examen varchar(50), 
	usr_usuarioid integer NOT NULL, 
	exa_opciones integer DEFAULT 5, 
	PRIMARY KEY(exa_examenid),
	FOREIGN KEY(usr_usuarioid) REFERENCES usuario (usr_usuarioid));

CREATE TABLE examen_fecha (
	exa_examenid integer NOT NULL, 
	exaf_fecharegistro timestamp DEFAULT 'now' NOT NULL, 
	exaf_duracion integer, 
	ecal_elementoid integer NOT NULL, 
	PRIMARY KEY(exa_examenid, exaf_fecharegistro),
	FOREIGN KEY(exa_examenid) REFERENCES examen (exa_examenid),
	FOREIGN KEY(ecal_elementoid) REFERENCES elemento_calificacion (ecal_elementoid));

CREATE TABLE grupo_elem_cal (
	ecal_elementoid integer NOT NULL, 
	grp_grupoid integer NOT NULL, 
	gec_fechaaplicacion timestamp NOT NULL, 
	PRIMARY KEY(ecal_elementoid, grp_grupoid),
	FOREIGN KEY(ecal_elementoid) REFERENCES elemento_calificacion (ecal_elementoid),
	FOREIGN KEY(grp_grupoid) REFERENCES grupo (grp_grupoid));

CREATE TABLE comenta_usuario (
	usr_usuarioid integer NOT NULL, 
	comu_fecharegistro timestamp DEFAULT 'now' NOT NULL, 
	comu_usuarioid integer NOT NULL, 
	comu_comentario varchar(300), 
	comu_tipo integer DEFAULT 0 NOT NULL CHECK(comu_tipo in (0,1,2,3,4,5)), 
	PRIMARY KEY(usr_usuarioid, comu_fecharegistro),
	FOREIGN KEY(usr_usuarioid) REFERENCES usuario (usr_usuarioid),
	FOREIGN KEY(comu_usuarioid) REFERENCES usuario (usr_usuarioid));

CREATE TABLE examen_aplicado (
	exa_examenid integer NOT NULL, 
	usr_usuarioid integer NOT NULL, 
	pre_preguntaid integer NOT NULL, 
	exap_fechahora timestamp DEFAULT 'now' NOT NULL, 
	res_respuestaid integer NOT NULL, 
	PRIMARY KEY(exa_examenid, usr_usuarioid, pre_preguntaid, exap_fechahora),
	FOREIGN KEY(exa_examenid) REFERENCES examen (exa_examenid),
	FOREIGN KEY(usr_usuarioid) REFERENCES usuario (usr_usuarioid),
	FOREIGN KEY(pre_preguntaid, res_respuestaid) REFERENCES pregunta_respuesta (pre_preguntaid, res_respuestaid));

CREATE TABLE examen_contenido (
	exa_examenid integer NOT NULL, 
	con_contenidoid integer NOT NULL, 
	uni_unidadid integer NOT NULL, 
	prog_programaid integer NOT NULL, 
	exac_nopreguntas integer NOT NULL, 
	exac_nivel integer DEFAULT 0 NOT NULL, 
	exco_opcionmultiple integer NOT NULL, 
	exco_relacioncolumnas integer NOT NULL, 
	exco_preguntasabiertas integer NOT NULL, 
	PRIMARY KEY(exa_examenid, con_contenidoid, uni_unidadid, prog_programaid),
	FOREIGN KEY(con_contenidoid, uni_unidadid, prog_programaid) REFERENCES contenido (con_contenidoid, uni_unidadid, prog_programaid),
	FOREIGN KEY(exa_examenid) REFERENCES examen (exa_examenid));

CREATE TABLE bitacora (
	bit_bitacoraid integer NOT NULL, 
	bit_fechahora timestamp DEFAULT 'now' NOT NULL, 
	bit_accion varchar(100), 
	usr_usuarioid integer NOT NULL, 
	PRIMARY KEY(bit_bitacoraid),
	FOREIGN KEY(usr_usuarioid) REFERENCES usuario (usr_usuarioid));

CREATE TABLE escuela_direccion_mx (
	esc_escuelaid integer UNIQUE NOT NULL, 
	colmx_coloniaid integer NOT NULL, 
	escmx_referencias varchar(300), 
	PRIMARY KEY(esc_escuelaid),
	FOREIGN KEY(esc_escuelaid) REFERENCES escuela (esc_escuelaid),
	FOREIGN KEY(colmx_coloniaid) REFERENCES colonia_mx (colmx_coloniaid));

CREATE TABLE colonia_mx (
	colmx_coloniaid integer NOT NULL, 
	colmx_colonia varchar(200) NOT NULL, 
	colmx_codigopostal integer NOT NULL, 
	munmx_municipioid integer NOT NULL, 
	PRIMARY KEY(colmx_coloniaid),
	FOREIGN KEY(munmx_municipioid) REFERENCES municipio_mx (munmx_municipioid));

CREATE TABLE municipio_mx (
	munmx_municipioid integer NOT NULL, 
	munmx_municipio varchar(200) NOT NULL, 
	edomx_estadoid integer NOT NULL, 
	PRIMARY KEY(munmx_municipioid),
	FOREIGN KEY(edomx_estadoid) REFERENCES estado_mx (edomx_estadoid));

CREATE TABLE estado_mx (
	edomx_estadoid integer NOT NULL, 
	edomx_estado varchar(200) NOT NULL, 
	PRIMARY KEY(edomx_estadoid));