Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 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_produtos int unsigned auto_increment,
  30. cod_categoria int,
  31. descricao varchar(100) binary not null,
  32. vlr_unit decimal(10,2) not null,
  33. primary key (cod_produtos)
  34. );
  35.  
  36. create table vendas (
  37. cod_venda int unsigned auto_increment,
  38. cod_funcionario int not null,
  39. cod_cliente int not null,
  40. vlr_total decimal(10,2) unsigned not null,
  41. data date not null,
  42. primary key (cod_venda)
  43. );
  44.  
  45. create table itens_venda (
  46. cod_venda int not null,
  47. item int not null,
  48. cod_produto int not null,
  49. qtd int unsigned not null,
  50. vlr_unit decimal(10, 2) not null,
  51. vlr_pedido decimal(10,2) GENERATED ALWAYS AS ((vlr_unit*qtd)) STORED,
  52. primary key (item, cod_venda)
  53. );
  54.  
  55. insert into clientes (nome, dt_nasc, cpf) values
  56. ("Arthur Felix", "2003-11-10", "07725082913"),
  57. ("Gustavo Nunes", "2002-11-09", "07893820139");
  58.  
  59. insert into funcionarios (matricula, nome, dt_adms, cargo) values
  60. ("84923", "Pedro Moratelli", "2018-08-10", "Vendedor"),
  61. ("019123", "Thiago SobrenomeDificil", "2019-10-10", "Gerente");
  62.  
  63. insert into vendas (cod_funcionario, cod_cliente, vlr_total, data) values
  64. (1, 2, 45, "2019-10-15"),
  65. (2, 1, 29, "2019-05-10");
  66.  
  67. insert into produtos values
  68. (null, 1, "Orquideas", 15.00),
  69. (null, 1, "Muda de Arvores", 25.00),
  70. (null, 2, "Vaso", 20.00),
  71. (null, 2, "Pa", 10.00),
  72. (null, 2, "Adubo", 8.00),
  73. (null, 3, "Cesto", 5.00),
  74. (null, 3, "Inseticida", 12.00);
  75.  
  76. insert into categorias values
  77. (null, "Plantas"),
  78. (null, "Jardinagem"),
  79. (null, "Outros");
  80.  
  81. insert into itens_venda (cod_venda, item, cod_produto, qtd, vlr_unit) values
  82. (1, 1, 1, 1, 15.00),
  83. (1, 2, 3, 1, 20.00),
  84. (1, 3, 4, 1, 10.00),
  85. (2, 1, 6, 1, 5.00),
  86. (2, 2, 7, 2, 12.00);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement