Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. create database if not exists lascanarias
  2. DEFAULT CHARACTER SET utf8
  3. DEFAULT COLLATE utf8_general_ci;
  4. SET NAMES utf8;
  5.  
  6. use lascanarias;
  7.  
  8. create table if not exists sucursal(
  9. cod int primary key auto_increment,
  10. localidad varchar(30))ENGINE=InnoDB;
  11.  
  12. create table if not exists usuario(
  13. user varchar(30) primary key,
  14. pass varchar(64),
  15. cod_suc int,
  16. CONSTRAINT Usuario_CodSuc_FK FOREIGN KEY(cod_suc)
  17. REFERENCES sucursal(cod));
  18.  
  19. create table if not exists vendedor(
  20. cod int primary key auto_increment,
  21. nombre varchar(30) not null,
  22. apellido varchar(30) not null,
  23. cod_suc int not null,
  24. CONSTRAINT Vendedor_CodSuc_FK FOREIGN KEY(cod_suc)
  25. REFERENCES sucursal(cod))ENGINE=InnoDB;
  26.  
  27. create table if not exists producto(
  28. descrip varchar(100) primary key,
  29. precio decimal(6,2));
  30.  
  31. create table if not exists transito(
  32. cod int primary key auto_increment,
  33. descrip varchar(40))ENGINE=InnoDB;
  34.  
  35. create table if not exists marca(
  36. cod int primary key auto_increment,
  37. nombre varchar(100))ENGINE=InnoDB;
  38.  
  39. create table if not exists calidad(
  40. descrip varchar(10) primary key);
  41.  
  42. create table if not exists medida(
  43. descrip varchar(9) primary key)ENGINE=InnoDB;
  44.  
  45. create table if not exists tipoventa(
  46. cod int auto_increment primary key,
  47. descrip varchar(30) not null
  48. );
  49.  
  50. create table if not exists ceramica(
  51. cod_trans int,
  52. cod_marca int,
  53. medida varchar(9),
  54. descrip varchar(100),
  55. calidad varchar(10),
  56. metros decimal(6,2) ,
  57. precio decimal(5,2),
  58. stock int,
  59. activo boolean not null,
  60. cod_suc int,
  61.  
  62. primary key(cod_marca,medida,descrip,calidad,cod_suc),
  63. index(cod_marca,medida,descrip,calidad,cod_suc),
  64. CONSTRAINT Ceramica_Transito_FK FOREIGN KEY(cod_trans)
  65. REFERENCES transito(cod),
  66. CONSTRAINT Ceramica_CodMarca_FK FOREIGN KEY(cod_marca)
  67. REFERENCES marca(cod),
  68. CONSTRAINT Ceramica_Medida_FK FOREIGN KEY(medida)
  69. REFERENCES medida(descrip),
  70. CONSTRAINT Ceramica_CodSuc_FK FOREIGN KEY(cod_suc)
  71. REFERENCES sucursal(cod),
  72. CONSTRAINT Ceramica_Calidad_FK FOREIGN KEY(calidad)
  73. REFERENCES calidad(descrip))ENGINE=InnoDB;
  74.  
  75. create table if not exists vende(
  76. cod_vend int,
  77. cod_marca int not null,
  78. medida varchar(9) not null,
  79. descrip varchar(100)not null,
  80. calidad varchar(10)not null,
  81. cant int not null,
  82. precio decimal(6,2) not null,
  83. fecha datetime,
  84. factura int not null,
  85. cod_tipo int not null,
  86. primary key(cod_vend,fecha),
  87. index(cod_marca,medida,descrip,calidad),
  88. CONSTRAINT Vende_CodVend_FK FOREIGN KEY(cod_vend)
  89. REFERENCES vendedor(cod),
  90. CONSTRAINT Vende_CodTipo_FK FOREIGN KEY(cod_tipo)
  91. REFERENCES tipoventa(cod),
  92. FOREIGN KEY Vende_Ceramica_FK(cod_marca,medida,descrip,calidad)
  93. REFERENCES ceramica(cod_marca,medida,descrip,calidad))ENGINE=InnoDB;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement