Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. create database floricultura;
  2.  
  3. use floricultura;
  4.  
  5. create table clientes (
  6. cod_cliente int unsigned auto_increment,
  7. nome varchar(100) not null,
  8. dt_nasc date null,
  9. cpf char(11) not null,
  10. primary key (cod_cliente),
  11. unique index cpf_unique (cpf)
  12. );
  13.  
  14. create table funcionarios (
  15. matricula int(8) zerofill,
  16. nome varchar(100) not null,
  17. dt_adms date not null,
  18. cargo varchar(30) not null,
  19. primary key (matricula)
  20. );
  21.  
  22. create table categorias (
  23. cod_categoria int unsigned auto_increment,
  24. descricao varchar(100) not null,
  25. primary key (cod_categoria)
  26. );
  27.  
  28. create table produtos (
  29. cod_produto int unsigned auto_increment,
  30. cod_categoria int unsigned,
  31. descricao varchar(100) binary not null,
  32. vlr_unit decimal(10,2) not null,
  33. primary key (cod_produto),
  34. index fk_produto_categoria_idx (cod_categoria),
  35. constraint fk_produto_categoria foreign key (cod_categoria) references categorias (cod_categoria)
  36. );
  37.  
  38. create table vendas (
  39. cod_venda int unsigned auto_increment,
  40. cod_funcionario int(8) zerofill,
  41. cod_cliente int unsigned not null,
  42. vlr_total decimal(10,2) unsigned not null,
  43. data date not null,
  44. primary key (cod_venda),
  45. index fk_vendas_funcionario_idx (cod_funcionario),
  46. index fk_vendas_cliente_idx (cod_cliente),
  47. constraint fk_vendas_funcionario foreign key (cod_funcionario) references funcionarios (matricula),
  48. constraint fk_vendas_cliente foreign key (cod_cliente) references clientes (cod_cliente)
  49. );
  50.  
  51. create table itens_venda (
  52. cod_venda int unsigned not null,
  53. item int not null,
  54. cod_produto int unsigned not null,
  55. qtd int unsigned not null,
  56. vlr_unit decimal(10, 2) not null,
  57. vlr_pedido decimal(10,2) GENERATED ALWAYS AS ((vlr_unit*qtd)) STORED,
  58. primary key (item, cod_venda),
  59. index fk_itensvenda_venda_idx (cod_venda),
  60. index fk_itensvenda_produto_idx (cod_produto),
  61. constraint fk_itensvenda_venda foreign key (cod_venda) references vendas (cod_venda),
  62. constraint fk_itensvenda_produto foreign key (cod_produto) references produtos (cod_produto)
  63. );
  64.  
  65. insert into clientes (nome, dt_nasc, cpf) values
  66. ("Arthur Felix", "2003-11-10", "07725082913"),
  67. ("Gustavo Nunes", "2002-11-09", "07893820139");
  68.  
  69. insert into funcionarios (matricula, nome, dt_adms, cargo) values
  70. ("84923", "Pedro Moratelli", "2018-08-10", "Vendedor"),
  71. ("019123", "Thiago SobrenomeDificil", "2019-10-10", "Gerente");
  72.  
  73. insert into categorias values
  74. (null, "Plantas"),
  75. (null, "Jardinagem"),
  76. (null, "Outros");
  77.  
  78. insert into produtos values
  79. (null, 1, "Orquideas", 15.00),
  80. (null, 1, "Muda de Arvores", 25.00),
  81. (null, 2, "Vaso", 20.00),
  82. (null, 2, "Pa", 10.00),
  83. (null, 2, "Adubo", 8.00),
  84. (null, 3, "Cesto", 5.00),
  85. (null, 3, "Inseticida", 12.00);
  86.  
  87. insert into vendas (cod_funcionario, cod_cliente, vlr_total, data) values
  88. (84923, 2, 45, "2019-10-15"),
  89. (019123, 1, 29, "2019-05-10");
  90.  
  91. insert into itens_venda (cod_venda, item, cod_produto, qtd, vlr_unit) values
  92. (1, 1, 1, 1, 15.00),
  93. (1, 2, 3, 1, 20.00),
  94. (1, 3, 4, 1, 10.00),
  95. (2, 1, 6, 1, 5.00),
  96. (2, 2, 7, 2, 12.00);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement