martinms

Hasil Normalisasi Pertemuan 1 (23 Februari 2023)

Feb 22nd, 2023 (edited)
1,330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.68 KB | None | 0 0
  1. drop table if exists kategoriProduk;
  2. create table kategoriProduk (
  3. id BIGINT(20) not null auto_increment primary key,
  4. nama varchar(255)
  5. );
  6. INSERT INTO `kategoriproduk` (`id`, `nama`) VALUES
  7. (1, 'Ponsel'),
  8. (2, 'Komputer'),
  9. (3, 'Memory');
  10.  
  11. drop table if exists produk;
  12. create table produk (
  13. id BIGINT(20) not null auto_increment primary key,
  14. idKategori BIGINT(20) null,
  15. nama varchar(255) not null,
  16. harga double(10, 2) not null,
  17. stok int(10) not null,
  18. diskon double(10, 2) null,
  19. foreign key (IDKategori) references kategoriProduk(ID) on delete cascade on update cascade
  20. );
  21. INSERT INTO `produk` (`id`, `idKategori`, `nama`, `harga`, `stok`, `diskon`) VALUES
  22. (1, 1, 'Redmi 9A', 1500000.00, 10, NULL),
  23. (2, 1, 'Oppo A53', 2000000.00, 10, NULL),
  24. (3, NULL, 'HP Pavilion 15', 9000000.00, 5, NULL);
  25.  
  26. drop table if exists supplier;
  27. create table supplier (
  28. id BIGINT(20) not null auto_increment primary key,
  29. nama varchar(255) not null,
  30. alamat varchar(255) not null,
  31. kota varchar(32) not null,
  32. no_telepon varchar(16) not null
  33. );
  34. INSERT INTO `supplier` (`id`, `nama`, `alamat`, `kota`, `no_telepon`) VALUES
  35. (1, 'PT ABC', 'Jl. ABC', 'Bengkulu', '08123'),
  36. (2, 'PT XYZ', 'Jl. XYZ', 'Palembang', '081234');
  37.  
  38. drop table if exists pembelian;
  39. create table pembelian (
  40. id BIGINT(20) not null auto_increment primary key,
  41. idSupplier bigint(20) null,
  42. no_nota varchar(16) not null unique,
  43. tanggal date not null,
  44. status_pembayaran enum('1', '2') default 1 comment '1=lunas, 2=belum lunas',
  45. metode_pembayaran varchar(32) not null,
  46. diskon double(10, 2) null,
  47. status_pengiriman enum('1', '2', '3') default 1 comment '1=belum dikirim, 2=dalam pengiriman, 3=sudah sampai',
  48. biaya_pengiriman double(10, 2) not null,
  49. total_harga double(10, 2) not null,
  50. keterangan text null,
  51. foreign key (idSupplier) references supplier (id) on delete set null on update cascade);
  52. INSERT INTO `pembelian` (`id`, `idSupplier`, `no_nota`, `tanggal`, `status_pembayaran`, `metode_pembayaran`, `diskon`, `status_pengiriman`, `biaya_pengiriman`, `total_harga`, `keterangan`) VALUES
  53. (1, 1, 'INV-123', '2023-08-03', '1', 'Transfer', NULL, '1', 300000.00, 14000000.00, NULL);
  54.  
  55. drop table if exists detailPembelian;
  56. create table detailPembelian (
  57. id BIGINT(20) not null auto_increment primary key,
  58. idPembelian BIGINT(20) null,
  59. idProduk BIGINT(20) null,
  60. jumlah_pembelian int(10) not null,
  61. harga double(10, 2) not null,
  62. foreign key (idPembelian) references pembelian (id) on delete cascade on update cascade,
  63. foreign key (idProduk) references produk (id) on delete cascade on update cascade);
  64. INSERT INTO `detailpembelian` (`id`, `idPembelian`, `idProduk`, `jumlah_pembelian`, `harga`) VALUES
  65. (1, 1, 1, 5, 1400000.00),
  66. (2, 1, 2, 5, 1900000.00);
Advertisement
Add Comment
Please, Sign In to add comment