Advertisement
CarlosWGama

LBD - PostgreSQL - DML

Dec 13th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Classes
  2. CREATE TABLE classes (
  3.     id serial primary key,
  4.     classe varchar
  5. );
  6.  
  7. INSERT INTO classes (classe) VALUES ('Guerreiro'), ('Mago'), ('Paladino'), ('Xamã');
  8.  
  9. -- Personagens
  10. CREATE TABLE personagens (
  11.     id serial primary key,
  12.     personagem varchar,
  13.     classe_id integer references classes(id),
  14.     hp smallint,
  15.     mp smallint,
  16.     forca smallint,
  17.     defesa smallint
  18. );
  19.  
  20.  
  21. INSERT INTO personagens (personagem,classe_id,hp,mp,forca,defesa) VALUES ('Brett',1,79,77,34,38),('Perry',3,94,25,16,11),('Nyssa',1,99,23,37,24),('Ella',1,84,50,4,37),('Bryar',2,88,58,23,10),('Tad',3,46,34,39,26),('Cruz',3,97,49,18,26),('Glenna',1,23,27,9,2),('Deacon',2,67,34,25,21),('Shelly',4,28,68,26,40),('Phillip',3,25,79,18,35),('Phelan',4,31,45,31,38),('Leah',4,48,12,30,4),('Erin',4,76,68,35,25),('Curran',3,94,47,24,2),('Clarke',1,26,45,10,12),('Ebony',1,63,43,16,17),('Maxine',3,23,19,26,40),('Ignatius',2,93,18,13,18),('Alan',3,96,21,33,18);
  22. INSERT INTO personagens (personagem,classe_id,hp,mp,forca,defesa) VALUES ('Dean',1,22,67,34,28),('Perry',4,89,63,39,29),('Reed',3,82,55,11,29),('Lacy',1,68,56,36,8),('Paula',2,28,27,14,11),('Carly',2,53,49,39,17),('Kenneth',1,21,69,18,5),('Athena',2,59,43,39,29),('Latifah',4,86,72,33,3),('Claudia',2,97,30,33,28),('Kermit',2,90,76,19,18),('Deborah',4,24,28,6,3),('Shafira',1,47,16,29,9),('Ivy',4,62,42,35,22),('Maya',1,47,25,4,25),('Hammett',3,20,47,31,37),('Theodore',1,24,11,26,38),('Adele',1,33,28,36,14),('Mercedes',3,97,44,26,15),('Naida',4,94,15,32,2);
  23.  
  24.  
  25.  
  26. -------- JOIN
  27. -- CATEGORIAS
  28. CREATE TABLE categorias (
  29.   id serial primary key,
  30.   nome character varying(200)
  31. );
  32.  
  33. insert into categorias(nome) values ('Terror'), ('Fantasia'), ('Ficção Cientifica'), ('Infantil');
  34.  
  35. -- LIVROS
  36.  
  37. CREATE TABLE livros (
  38.   id serial primary key,
  39.   titulo character varying(200),
  40.   preco money,
  41.   categoria_id integer REFERENCES categorias
  42. );
  43.  
  44. insert into livros (titulo, preco, categoria_id)
  45.         values ('IT', 70.00, 1), ('Harry Potter e a Câmara Secreta', 50.00, 2),
  46.                ('Senhor dos Anéis', 150.00, 2), ('Código da Vinci', 45.00, 3), ('O Alquimista',  40.00, 3);
  47.  
  48. insert into livros (titulo, preco)
  49.         values ('O Pequeno Principe', 30.00);
  50.  
  51.  
  52. -- ALUNOS
  53. create table alunos (
  54.     id serial primary key,
  55.     nome varchar(200),
  56.     ativo boolean
  57. );
  58.  
  59. insert into alunos (nome, ativo) values ('Thiago', '1'), ('João', '0'), ('Mario', '1'), ('Flávio', '0');
  60.  
  61.  
  62. -- Notas
  63. create table notas (
  64.     aluno_id integer references alunos,
  65.     nota1 numeric(4,2),
  66.     nota2 numeric(4,2),
  67.     nota3 numeric(4,2)
  68. );
  69.  
  70. insert into notas values (1, 5, 7.5, 9.5), (2, 8.5, 8.5, 6), (3, 10, 3.5, 6);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement