0% found this document useful (0 votes)
4 views

SQL_Script_Output

The document outlines the creation of a database schema with four tables: Pelanggan (customers), Barang (items), Invoice (invoices), and Detail_Invoice (invoice details). It includes SQL commands to create these tables and insert sample data for customers, items, invoices, and invoice details. The schema establishes relationships between the tables through foreign keys.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

SQL_Script_Output

The document outlines the creation of a database schema with four tables: Pelanggan (customers), Barang (items), Invoice (invoices), and Detail_Invoice (invoice details). It includes SQL commands to create these tables and insert sample data for customers, items, invoices, and invoice details. The schema establishes relationships between the tables through foreign keys.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

One pailer no 3

CREATE TABLE Pelanggan (


id_pelanggan VARCHAR(5) PRIMARY KEY,
nama_pelanggan VARCHAR(50),
kota_pelanggan VARCHAR(50),
no_handphone VARCHAR(15)
);

INSERT INTO Pelanggan (id_pelanggan, nama_pelanggan, kota_pelanggan, no_handphone) VALUES


('P001', 'Ani', 'Jakarta', '081234567891'),
('P002', 'Budi', 'Surabaya', '082345678912'),
('P003', 'Caca', 'Bandung', '083456789123'),
('P004', 'Dewi', 'Yogyakarta', '084567891234'),
('P005', 'Eka', 'Semarang', '085678912345'),
('P006', 'Fitria', 'Denpasar', '08679123456'),
('P007', 'Guntur', 'Medan', '08789123456'),
('P008', 'Hadi', 'Makassar', '088912345678'),
('P009', 'Indah', 'Palembang', '08123456789'),
('P010', 'John', 'Balikpapan', '081234567890');

CREATE TABLE Barang (


id_barang VARCHAR(5) PRIMARY KEY,
nama_barang VARCHAR(50),
harga_satuan INT(8)
);

INSERT INTO Barang (id_barang, nama_barang, harga_satuan) VALUES


('B001', 'Beras', 10000),
('B002', 'Gula', 8000),
('B003', 'Minyak Goreng', 15000),
('B004', 'Telur', 20000),
('B005', 'Sabun Mandi', 5000),
('B006', 'Pasta Gigi', 7000),
('B007', 'Shampoo', 10000),
('B008', 'Sikat Gigi', 3000);

CREATE TABLE Invoice (


nomor_invoice VARCHAR(10) PRIMARY KEY,
tanggal_pembelian DATE,
id_pelanggan VARCHAR(10),
FOREIGN KEY (id_pelanggan) REFERENCES Pelanggan(id_pelanggan)
);

INSERT INTO Invoice (nomor_invoice, tanggal_pembelian, id_pelanggan) VALUES


('INV001','2024-03-23','P001'),
('INV002','2024-03-23','P002'),
('INV003','2024-03-23','P003'),
('INV004','2024-03-23','P004'),
('INV005','2024-03-23','P005'),
('INV006','2024-03-23','P006'),
('INV007','2024-03-23','P007');

CREATE TABLE Detail_Invoice


( nomor_invoice VARCHAR(10),
id_barang VARCHAR(10),
jumlah INT,
PRIMARY KEY (nomor_invoice, id_barang),
FOREIGN KEY (nomor_invoice) REFERENCES Invoice(nomor_invoice),
FOREIGN KEY (id_barang) REFERENCES Barang(id_barang)
);

INSERT INTO Detail_Invoice (nomor_invoice, id_barang, jumlah) VALUES


('INV001','B001',2),
('INV001','B002',1),
('INV002','B001',1),
('INV002','B003',2),
('INV003','B004',1),
('INV004','B005',3),
('INV005','B002',1),
('INV005','B003',3),
('INV006','B003',4),
('INV007','B004',1);

You might also like