1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| drop table if exists `candidats` ;
drop table if exists `users` ;
--
create table users (
user_id bigint not null auto_increment,
login varchar(255) not null unique,
primary key (user_id)
) type=innodb ;
--
create table candidats (
user_id bigint not null,
foreign key (user_id) references users(user_id),
primary key (user_id),
nom varchar(255) not null,
prenom varchar(255) not null
) type=innodb ;
--
insert into users (login) values ('test') ;
insert into candidats (user_id,nom,prenom) values ((select user_id from users where login='test'),'fou','testeur') ;
--
drop view if exists `view_candidats` ;
create view view_candidats as
select u.user_id,u.login,c.nom,c.prenom from users u, candidats c where c.user_id=u.user_id ;
--
select * from view_candidats ;
--
delimiter |
drop procedure if exists `insert_candidats`|
create procedure insert_candidats (
in _login varchar(255),
in _nom varchar(255),
in _prenom varchar(255)
)
begin
declare _id bigint(20) ;
insert into users (login) values (_login) ;
commit ;
select last_insert_id() into _id ;
insert into candidats (user_id,nom,prenom) values (_id,_nom,_prenom) ;
end|
delimiter ;
--
call insert_candidats('anonymous','Onyme','Anne') ;
select * from view_candidats ; |
Partager