He estado atrapado durante horas y horas en el mismo problema... para que vean de que trata:
Código:
No tengo idea como crear un procedimiento almacenado que me permita registrar los datos de manera automatica. Un pseudocodigo que NO funciona:/*==================================================*/ create table user ( ID_USER int not null auto_increment, FIRSTNAME varchar(50) default NULL, LASTNAME varchar(50) default NULL, primary key (ID_USER) ) type = InnoDB; /*==================================================*/ create table student ( ID_USER int not null, ADVTYPE varchar(50), primary key (ID_USER) ) type = InnoDB; /*==================================================*/ alter table student add constraint FK_USER_STUDENT foreign key (ID_USER) references user (ID_USER) on delete restrict on update restrict;
Código:
Como podran ver, necesito seleccionar el "ultimo ID_USER" para poder realizar la operacion... alguien sabe como? USE rania DELIMITER // DROP PROCEDURE IF EXISTS `test`// CREATE PROCEDURE `test`() BEGIN; INSERT INTO user (FIRSTNAME, LASTNAME) VALUES (`nombre`, `apellido`); INSERT INTO student (ID_USER, ADVTYPE) VALUES (SELECT LAST ID_USER,`asd`); COMMIT; END//
