MySQL Forums
Forum List  »  Spanish

Error básico !!!
Posted by: Juan Molina Castellanos
Date: January 10, 2014 12:28PM

Saludos, tengo una duda básica ya que desde hace tiempo no hago bases de datos, el problema es el siguiente:

tengo una tabla de alumnos con datos personales de los alumnos, tengo una tabla de alumnos_internos y otra tabla alumnos_externos (con datos laborales de los alumnos), creo estas dos tablas ya que para los alumnos_internos me piden almacenar su puesto, antiguedad en el cargo y jefe inmediato entre otros, mientras que para los alumnos_externos me piden almacenar el nombre de la empresa, la direccion de la empresa entre otros, MI DUDA ES, ¿ es correcto generar una tabla alumnos_internos y una tabla alumnos_externos ? ya que se almacena distinta información o ¿ debiera crear las tablas de otra forma ? , me piden listar todos los alumnos tanto internos como externos en una lista por medio de una consulta, si todo estubiera en una sola tabla el problema se reduciría a un:

SELECT * from alumnos_todos

pero en este caso que se tienen 2 tablas con distintos campos ¿ como poner las 2 tablas en el listado ? ¿ la solución tendría que ver con un UNION ?

SELECT * from alumnos_internos Where 1=1
UNION
SELECT * from alumnos_externos where 1=1

las tablas son las siguientes:

CREATE TABLE `alumno` (
`idAlumno` int(11) NOT NULL AUTO_INCREMENT,
`idTipoUsuario` int(11) NOT NULL,
`nombre` varchar(80) NOT NULL,
`apPaterno` varchar(80) NOT NULL,
`apMaterno` varchar(80) NOT NULL,
`sexo` varchar(1) NOT NULL,
`calle_num` varchar(50) NOT NULL,
`colonia` varchar(50) NOT NULL,
`ciudad` varchar(50) NOT NULL,
`del_muni` varchar(50) NOT NULL,
`localidad` varchar(50) DEFAULT NULL,
`telefono_fijo` varchar(20) DEFAULT NULL,
`celular` varchar(30) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`universidad_proc` varchar(80) DEFAULT NULL,
`mod_titulacion` varchar(50) DEFAULT NULL,
`fecha_titulacion` date DEFAULT NULL,
`promedio_gen` float DEFAULT NULL,
`fecha_registro` date DEFAULT NULL,
PRIMARY KEY (`idAlumno`),
KEY `idTipoUsuario` (`idTipoUsuario`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


CREATE TABLE IF NOT EXISTS `alumno_externo` (
`idAlumno` int(11) NOT NULL AUTO_INCREMENT,
`nombre_lugar_trabajo` varchar(150) DEFAULT NULL,
`direccion` varchar(250) NOT NULL,
`telefono_trab` varchar(20) NOT NULL,
`extension` varchar(10) NOT NULL,
PRIMARY KEY (`idAlumno`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


CREATE TABLE IF NOT EXISTS `alumno_interno` (
`idAlumno` int(11) NOT NULL AUTO_INCREMENT,
`idAdscripcion` int(11) NOT NULL,
`idPuesto` int(11) NOT NULL,
`extension` varchar(10) NOT NULL,
`antig_cargo` varchar(40) NOT NULL,
`nombre_titular` varchar(240) NOT NULL,
PRIMARY KEY (`idAlumno`),
KEY `idAdscripcion` (`idAdscripcion`),
KEY `idPuesto` (`idPuesto`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Otra duda es ¿ Es correcto que las 3 tablas tengan el idUsuario como llave primaria ?

Options: ReplyQuote


Subject
Views
Written By
Posted
Error básico !!!
2540
January 10, 2014 12:28PM
788
January 10, 2014 04:00PM
722
January 13, 2014 10:08AM
706
January 13, 2014 10:41AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.