Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. create schema if not exists Faculdade;
  2.  
  3. use faculdade;
  4.  
  5. create table if not exists Alunos
  6. (
  7. RA integer UNSIGNED not null,
  8. senha varchar(15) not null,
  9. nome varchar(100) not null,
  10. faltas integer,
  11. PRIMARY KEY (RA)
  12. )ENGINE = InnoDB;
  13.  
  14. create table if not exists Materias
  15. (
  16. id SMALLINT UNSIGNED NOT NULL,
  17. nome varchar(50) not null,
  18. nota1 float,
  19. nota2 float,
  20. medias float,
  21. substitutiva float,
  22. RA integer UNSIGNED not null,
  23. primary key(id,RA)
  24. )ENGINE = InnoDB;
  25.  
  26.  
  27. ALTER TABLE `Materias` ADD CONSTRAINT `RA` FOREIGN KEY ( `RA` ) REFERENCES `Alunos` ( `RA` ) ;
  28.  
  29. drop database faculdade;
  30.  
  31. describe Alunos;
  32.  
  33. describe Materias;
  34.  
  35. insert into Alunos values(201500983,'12345','Marcos Paes Leme',0);
  36. insert into Alunos values(201500984,'54321','Dionizio',0);
  37. insert into Alunos values(201500985,'1357','Paulo José',0);
  38. insert into Alunos values(201500986,'2468','Robervau',0);
  39.  
  40. select * from Alunos;
  41.  
  42. insert into Materias values(1,'Alged',6.0,7.0,(select sum(nota1+nota2)/2 from Materias where RA = 201500984),0.0,(select RA from Alunos where RA=201500984));
  43. insert into Materias values(1,'Alged',6.0,7.0,(select sum(nota1+nota2)/2 from Materias where RA = 201500984),0.0,(select RA from Alunos where RA=201500984));
  44. select * from Materias;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement