Advertisement
xlrnxnlx

AAPdb

May 14th, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE category (
  2.     id NUMBER NOT NULL CONSTRAINT pk_category PRIMARY KEY,
  3.     genre VARCHAR2(100)
  4. )
  5.  
  6. INSERT INTO category VALUES (1, 'Aeronáutica [AVIAÇÃO]');
  7. INSERT INTO category VALUES (2, 'Aviação Civil');
  8. INSERT INTO category VALUES (3, 'Aviação Comercial');
  9. INSERT INTO category VALUES (4, 'Aviação Militar');
  10. INSERT INTO category VALUES (5, 'Aviação Geral');
  11. INSERT INTO category VALUES (6, 'Linhas Aéreas');
  12.  
  13. SELECT * FROM category; -- ok
  14.  
  15. CREATE TABLE pilot(
  16.     brevet NUMBER NOT NULL PRIMARY KEY,
  17.     fname VARCHAR(50) NOT NULL,
  18.     lname VARCHAR(150),
  19.     entry DATE DEFAULT SYSDATE NOT NULL,
  20.     pilotcategory NUMBER NOT NULL,
  21.         CONSTRAINT fk_pilotcat FOREIGN KEY (pilotcategory) REFERENCES category(id)
  22. );
  23.  
  24. INSERT INTO pilot VALUES (1, 'Márcio', 'Santos', '10-02-2001', 1);
  25. INSERT INTO pilot VALUES (2, 'Marcelo', 'Alves', '12-05-2004', 2);
  26. INSERT INTO pilot VALUES (3, 'Mariana', 'Juana', '12-08-2005', 2);
  27. INSERT INTO pilot VALUES (4, 'Karine', 'Gomes', '20-12-2002', 3);
  28. INSERT INTO pilot VALUES (5, 'Rodrigo', 'Lins', '25-10-2001', 1);
  29. INSERT INTO pilot VALUES (6, 'João', 'Augusto', '18-06-2000', 4);
  30.  
  31. SELECT * FROM pilot; -- ok
  32.  
  33. CREATE TABLE airplanecategory (
  34.     id NUMBER NOT NULL PRIMARY KEY,
  35.     genre VARCHAR2(100)
  36. )
  37.  
  38. INSERT INTO airplanecategory VALUES (1, 'Civil');
  39. INSERT INTO airplanecategory VALUES (2, 'Militar');
  40. INSERT INTO airplanecategory VALUES (3, 'Experimental');
  41. INSERT INTO airplanecategory VALUES (4, 'Hidro');
  42. INSERT INTO airplanecategory VALUES (5, 'Supersônico');
  43.  
  44. SELECT * FROM airplanecategory; -- ok
  45.  
  46. CREATE TABLE airplane (
  47.     id NUMBER NOT NULL PRIMARY KEY,
  48.     category NUMBER NOT NULL,
  49.     capacity NUMBER NOT NULL,
  50.     CONSTRAINT fk_airplane FOREIGN KEY(category) REFERENCES airplanecategory(id)
  51. );
  52.  
  53. INSERT INTO airplane VALUES (1, 1, 500);
  54. INSERT INTO airplane VALUES (2, 2, 1);
  55. INSERT INTO airplane VALUES (3, 2, 20);
  56. INSERT INTO airplane VALUES (4, 1, 200);
  57. INSERT INTO airplane VALUES (5, 4, 4);
  58. INSERT INTO airplane VALUES (6, 1, 650);
  59.  
  60. SELECT * FROM airplane; -- ok
  61.  
  62. CREATE TABLE travel(
  63.     brevet NUMBER NOT NULL,
  64.     plane NUMBER NOT NULL,
  65.     tdate DATE DEFAULT SYSDATE NOT NULL,
  66.     location VARCHAR2(100),
  67.     CONSTRAINT fk_travel_brevet FOREIGN KEY (brevet) REFERENCES pilot(brevet),
  68.     CONSTRAINT fk_travel_plane FOREIGN KEY (plane) REFERENCES airplane(id)
  69. );
  70.  
  71. INSERT INTO travel VALUES (1, 1, '10-10-2010', 'Brasil');
  72. INSERT INTO travel VALUES (2, 3, '10-11-2008', 'Holanda');
  73. INSERT INTO travel VALUES (2, 3, '12-02-2011', 'México');
  74. INSERT INTO travel VALUES (4, 2, '20-01-2005', 'Argentina');
  75. INSERT INTO travel VALUES (1, 4, '11-06-2000', 'Estados Unidos');
  76. INSERT INTO travel VALUES (3, 1, '19-10-2011', 'Argentina');
  77.  
  78. SELECT * FROM travel; -- ok
  79.  
  80. -- :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement