Advertisement
ismoy

ejercicio base de datos

Nov 21st, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. create table FABRICANTE
  2. (codigo number(20) not null primary key,
  3. nombre varchar2(20) not null,
  4. pais varchar2(20) not null,
  5. fecha date not null);
  6.  
  7. create table VENDEDOR
  8. (id_vendedor number(10) not null primary key,
  9. rut_vendedor varchar2(20) not null,
  10. drut_vendedor char(1) not null,
  11. id_dueno number(10) not null,
  12. nombre varchar2(20) not null,
  13. apellido varchar2(20) not null,
  14. telefono number(20) not null,
  15. fecha_contrato date not null);
  16.  
  17. create table BOLETA
  18. (nro_boleta number(10) not null primary key,
  19. id_vendedor number(10) not null,
  20. fecha_boleta date not null,
  21. monto_boleta number(10),
  22. CONSTRAINT FK_BOLETA_VENDEDOR FOREIGN KEY(id_vendedor) REFERENCES VENDEDOR(id_vendedor));
  23.  
  24. create table DETALLE_BOLETA
  25. (id_detalle number(10) not null primary key,
  26. nro_boleta number(10) not null,
  27. cantidad number(10) not null,
  28. valor_unitario number(15,5) not null,
  29. valor_total number(15,5) not null,
  30. CONSTRAINT FK_DETALLE_BOLETA_BOLETA FOREIGN KEY(nro_boleta) REFERENCES BOLETA(nro_boleta));
  31.  
  32. create table ESTADISTICAS
  33. (id_estadisticas number(20) not null primary key,
  34. nro_boleta number(10) not null,
  35. numero_ventas number(10) not null,
  36. monto_vendido number(10) not null,
  37. CONSTRAINT FK_ESTADISTICAS_BOLETA FOREIGN KEY(nro_boleta) REFERENCES BOLETA(nro_boleta));
  38.  
  39. create table AUTOMOVIL
  40. (codigo_automovil number(20) not null primary key,
  41. modelo varchar2(15) not null,
  42. combustible varchar2(15) not null,
  43. valor number(20) not null,
  44. asientos number(20) not null,
  45. fecha_auto date not null,
  46. codigo number(20),
  47. CONSTRAINT FK_AUTOMOVIL_FABRICANTE FOREIGN KEY(codigo) REFERENCES FABRICANTE(codigo));
  48.  
  49. create table DUENO
  50. (id_dueno number(10) not null primary key,
  51. codigo_automovil number(10) not null,
  52. nombre_dueno varchar2(50) not null,
  53. edad number(10) not null,
  54. telefono number(15) not null,
  55. direccion varchar2(200) not null,
  56. CONSTRAINT FK_DUENO_AUTOMOVIL FOREIGN KEY(codigo_automovil) REFERENCES AUTOMOVIL(codigo_automovil));
  57.  
  58.  
  59.  
  60. create table GARANTIA
  61. (id_garantia number(20) not null primary key,
  62. codigo_automovil number(10) not null,
  63. monto_garantia number(10) not null,
  64. tiempo_garantia number(10) not null,
  65. CONSTRAINT FK_GARANTIA_AUTOMOVIL FOREIGN KEY(codigo_automovil) REFERENCES AUTOMOVIL(codigo_automovil));
  66.  
  67.  
  68. create table REPUESTOS
  69. (codigo_repuestos number(10) not null primary key,
  70. nombre varchar2(40) not null,
  71. valor number(10) not null,
  72. descuento number(10) not null,
  73. codigo_automovil number(20) not null,
  74. CONSTRAINT FK_REPUESTOS_AUTOMOVIL FOREIGN KEY(codigo_automovil) REFERENCES AUTOMOVIL(codigo_automovil));
  75.  
  76.  
  77. CREATE SEQUENCE SEQ_PRUEBA3
  78. INCREMENT BY 10
  79. START WITH 100;
  80.  
  81. INSERT INTO AUTOMOVIL(codigo_automovil)
  82. VALUES (SEQ_PRUEBA3.NEXTVAL);
  83.  
  84. insert into FABRICANTE values(10001,'mercedez','alemania','05/05/11');
  85. insert into FABRICANTE values(10002,'ford','EEUU','05/05/12');
  86. insert into FABRICANTE values(10003,'ferrari','italia','05/05/13');
  87.  
  88. insert into AUTOMOVIL values(123,'AX123','gasolina98',25000000,5,'05/05/2011',10001);
  89. insert into AUTOMOVIL values(124,'AX124','gasolina98',26000000,4,'05/05/2012',10002);
  90. insert into AUTOMOVIL values(125,'AX125','gasolina98',27000000,5,'05/05/2013',10003);
  91.  
  92. insert into REPUESTOS values(20002,'tubo de escape',350000,5,123);
  93. insert into REPUESTOS values(20003,'asiento',220000,7,124);
  94. insert into REPUESTOS values(20004,'radio',150000,5,125);
  95.  
  96.  
  97. insert into DUENO values(20002,123,'juanito',37,45664837,'av. etc1');
  98. insert into DUENO values(20003,124,'pepito',38,45664838,'av. etc2');
  99. insert into DUENO values(20004,125,'pedrito',39,45664839,'av. etc3');
  100.  
  101. insert into VENDEDOR values(51001,66666666,6,20002,'alex','perez',45654325,'05/04/08');
  102. insert into VENDEDOR values(51002,77777777,7,20003,'alex','perez',45654326,'05/04/08');
  103. insert into VENDEDOR values(51003,88888888,8,20004,'alex','perez',45654327,'05/04/08');
  104.  
  105. insert into BOLETA values(80000001,51001,'05/07/07',25000000);
  106. insert into BOLETA values(80000002,51002,'05/07/08',26000000);
  107. insert into BOLETA values(80000003,51003,'05/07/09',27000000);
  108.  
  109. insert into DETALLE_BOLETA values(123456,80000001,5,25000000,20250000);
  110. insert into DETALLE_BOLETA values(123457,80000002,6,24000000,19440000);
  111. insert into DETALLE_BOLETA values(123458,80000003,5,27000000,17820000);
  112.  
  113. insert into GARANTIA values (457001,123,120000,12);
  114. insert into GARANTIA values (457002,124,100000,12);
  115. insert into GARANTIA values (457003,125,110000,12);
  116.  
  117. insert into ESTADISTICAS values (280101,80000001,3,57510000);
  118. insert into ESTADISTICAS values (280102,80000002,3,57510000);
  119. insert into ESTADISTICAS values (280103,80000003,3,57510000);
  120.  
  121. SELECT rut_vendedor||'-'||drut_vendedor ||' '|| nombre ||' '|| apellido||' '|| fecha_contrato
  122. FROM VENDEDOR;
  123.  
  124.  
  125. UPDATE BOLETA
  126. SET salary = salary *1.25
  127. WHERE monto_boleta > 150000;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement