Anda di halaman 1dari 5

CREATE DATABASE DBPENJUALAN0079 ON

( NAME = DBPENJUALAN0079_dat,

FILENAME = 'D:\17.12.0079\DBPENJUALAN0079.mdf',

SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5 ) LOG ON

( NAME = 'DBPENJUALAN0016_log',

FILENAME = 'D:\17.12.0079\DBPENJUALAN0079.ldf',

SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB

)

USE DBPENJUALAN0079

CREATE TABLE BARANG( KODE_BARANG CHAR(5) PRIMARY KEY NOT NULL, NAMA_BARANG VARCHAR(50) NOT NULL, HARGA_SATUAN NUMERIC(18,0) NOT NULL)

CREATE TABLE PELANGGAN( KD_PELANGGAN CHAR(5) PRIMARY KEY NOT NULL, NAMA_PELANGGAN VARCHAR(100) NOT NULL, ALAMAT VARCHAR(100) NOT NULL, NO_TELPON VARCHAR(12) )

CREATE TABLE KASIR( KD_KASIR CHAR(5) PRIMARY KEY NOT NULL, NAMA_KASIR VARCHAR(100) NOT NULL, PASSWORD VARCHAR(30) NOT NULL,)

CREATE TABLE NOTA ( NO_NOTA CHAR(5) PRIMARY KEY NOT NULL, KD_PELANGGAN CHAR(5) FOREIGN KEY REFERENCES PELANGGAN (KD_PELANGGAN) NOT NULL, KD_KASIR CHAR(5) FOREIGN KEY REFERENCES KASIR (KD_KASIR) NOT NULL,)

CREATE TABLE DETAIL_NOTA ( KD_NOTA CHAR(5) FOREIGN KEY REFERENCES NOTA (NO_NOTA) NOT NULL,

KD_BARANG CHAR(5) FOREIGN KEY REFERENCES BARANG (KODE_BARANG) NOT NULL, JUMLAH_BARANG INT NOT NULL, TGL_TRANSAKSI DATETIME NOT NULL

)

SELECT * FROM DETAIL_NOTA SELECT * FROM NOTA SELECT * FROM BARANG SELECT * FROM PELANGGAN SELECT * FROM KASIR

ALTER TABLE DETAIL_NOTA DROP COLUMN TGL_TRANSAKSI;

ALTER TABLE NOTA ADD TGL_NOTA DATETIME ;

ALTER TABLE DETAIL_NOTA ADD HARGA_BARANG NUMERIC(18,2) ;

ALTER TABLE KASIR ALTER COLUMN NAMA_KASIR VARCHAR (50)

INSERT INTO BARANG VALUES ('B0001','RINSO 50 GRAM','3000') INSERT INTO BARANG VALUES ('B0002','NESTLE 300 ML','2500') INSERT INTO BARANG VALUES ('B0003','TARO 450 GRAM','8500') INSERT INTO BARANG VALUES ('B0004','BOLPEN SNOWMAN','1500') INSERT INTO BARANG VALUES ('B0005','GULAKU 1 KG','20000')

INSERT INTO KASIR VALUES ('K0001','KARNO','ABC123') INSERT INTO KASIR VALUES ('K0002','MIMA','JESICA123')

INSERT INTO PELANGGAN VALUES ('P0001','APRILLIA','BANTUL','0812000111') INSERT INTO PELANGGAN VALUES ('P0002','ZULKAMAIN','YOGYAKARTA',NULL) INSERT INTO PELANGGAN VALUES ('P0003','ANDIKA','SLEMAN','') INSERT INTO PELANGGAN VALUES ('P0004','PAMO','YOGYAKARTA','0856222999')

ALTER TABLE KASIR ADD LEVEL_KASIR CHAR(2) ; ALTER TABLE BARANG ADD STOK INT ;

insert into kasir values ('K0003','Mirnawati rahmasari','mirna5678',NULL) insert into kasir values ('K0004','Endang sari sukarno','endang123',NULL) insert into kasir values ('K0005','Edi rahmawan','edi99',NULL)

insert into pelanggan values ('P0005','Indah','Yogya',null) insert into pelanggan values ('P0006','Raihan eka', 'Sleman',null) insert into pelanggan values ('P0007','Ekasari','Yogya', '876265')

insert into barang values ('B0006','Rinso 100 gram',5000,NULL) insert into barang values ('B0007','Detergen cair Rinso 100 ml',6000,NULL) insert into barang values ('B0008','Gulaku stick',1000,NULL)

insert into NOTA values('N0001','P0001','K0001','2019-03-03 10:15:00') insert into NOTA values('N0002','P0002','K0002','2019-03-04 10:10:00') insert into NOTA values('N0003','P0004','K0002','2019-03-04 10:13:00') insert into NOTA values('N0004','P0001','K0004','2019-03-05 11:15:00') insert into NOTA values('N0005','P0004','K0001','2019-03-05 15:20:00') insert into NOTA values('N0006','P0002','K0004','2019-03-05 15:25:00') insert into NOTA values('N0007','P0003','K0002','2019-03-06 12:03:00')

insert into detail_nota values('N0001','B0001',3,2850) insert into detail_nota values('N0001','B0002',2,2500) insert into detail_nota values('N0001','B0005',1,18500) insert into detail_nota values('N0002','B0007',1,6000) insert into detail_nota values('N0003','B0003',2,8450) insert into detail_nota values('N0003','B0004',10,1500) insert into detail_nota values('N0004','B0001',3,2800) insert into detail_nota values('N0004','B0008',10,1000) insert into detail_nota values('N0004','B0003',1,8500) insert into detail_nota values('N0005','B0003',5,8500) insert into detail_nota values('N0006','B0007',1,6000) insert into detail_nota values('N0006','B0002',1,2500) insert into detail_nota values('N0006','B0005',1,20000) insert into detail_nota values('N0007','B0003',4,8500)

SELECT * FROM DETAIL_NOTA SELECT * FROM NOTA SELECT * FROM BARANG

SELECT * FROM PELANGGAN SELECT * FROM KASIR

5

UPDATE KASIR SET LEVEL_KASIR = 'AK' WHERE KD_KASIR = 'K0001'

6

UPDATE KASIR SET LEVEL_KASIR = 'SK' WHERE KD_KASIR <> 'K0001'

7

UPDATE BARANG SET STOK=100

8

UPDATE KASIR SET PASSWORD='jogja0912' WHERE NAMA_KASIR='KARNO'

9

UPDATE PELANGGAN SET NAMA_PELANGGAN='ANDIKA ZULKAMAIN' ,ALAMAT='JL.NUSA INDAH 101 CONCAT DEPOK SLEMAN', NO_TELPON = '08192936666' WHERE

NAMA_PELANGGAN='ANDIKA'

10

UPDATE BARANG SET HARGA_SATUAN=21500 WHERE KODE_BARANG = 'B0005'

11

DELETE PELANGGAN WHERE KD_PELANGGAN='P0007'

12

UPDATE PELANGGAN SET ALAMAT ='YOGYAKARTA' WHERE ALAMAT = 'YOGYA'

13

SELECT KD_KASIR,NAMA_KASIR FROM KASIR WHERE NAMA_KASIR LIKE '%Mirna%'

14

SELECT KD_PELANGGAN,NAMA_PELANGGAN,NO_TELPON FROM PELANGGAN WHERE NO_TELPON IS NOT NULL

15

SELECT DISTINCT (ALAMAT) FROM PELANGGAN

16

SELECT * FROM BARANG ORDER BY NAMA_BARANG ASC

17

SELECT KODE_BARANG,NAMA_BARANG,HARGA_SATUAN FROM BARANG WHERE HARGA_SATUAN > 3000

18

SELECT KODE_BARANG,NAMA_BARANG,HARGA_SATUAN FROM BARANG WHERE NAMA_BARANG LIKE '%RINSO%'

19

SELECT SUM (STOK) FROM BARANG

20

SELECT N.NO_NOTA,N.TGL_NOTA,P.NAMA_PELANGGAN

FROM NOTA N JOIN PELANGGAN P ON n.KD_PELANGGAN = p.KD_PELANGGAN WHERE P.KD_PELANGGAN = 'P0001' OR p.KD_PELANGGAN = 'P0004'

21

SELECT b.KODE_BARANG,b.NAMA_BARANG, SUM(d.JUMLAH_BARANG) AS JUMLAH_TERJUAL FROM BARANG b JOIN DETAIL_NOTA d ON b.KODE_BARANG = d.KD_BARANG GROUP BY b.KODE_BARANG, b.NAMA_BARANG

22

SELECT p.NAMA_PELANGGAN,p.KD_PELANGGAN, COUNT(n.NO_NOTA) AS JUMLAH_TRANSAKSI FROM PELANGGAN p JOIN NOTA n ON p.KD_PELANGGAN = n.KD_PELANGGAN GROUP BY p.NAMA_PELANGGAN,p.KD_PELANGGAN ORDER BY COUNT (n.NO_NOTA) DESC

23

SELECT n.NO_NOTA, n.TGL_NOTA, p.NAMA_PELANGGAN, COUNT(n.NO_NOTA)AS TOTAL_TRANSAKSI,

SUM(d.JUMLAH_BARANG) FROM NOTA n JOIN PELANGGAN p

ON n.KD_PELANGGAN = p.KD_PELANGGAN JOIN DETAIL_NOTA d ON n.NO_NOTA = d.KD_NOTA GROUP BY n.NO_NOTA,n.TGL_NOTA,p.NAMA_PELANGGAN ORDER BY COUNT (n.NO_NOTA)DESC

24

SELECT N.NO_NOTA, n.TGL_NOTA, p.NAMA_PELANGGAN ,COUNT (N.NO_NOTA)AS TOTAL_TRANSAKSI FROM NOTA n JOIN PELANGGAN p ON N.KD_PELANGGAN = P.KD_PELANGGAN WHERE P.KD_PELANGGAN='P0002' GROUP BY N.NO_NOTA,N.TGL_NOTA,P.NAMA_PELANGGAN

25.

SELECT N.NO_NOTA, D.KD_BARANG, B.NAMA_BARANG, D.JUMLAH_BARANG, D.HARGA_BARANG, (D.JUMLAH_BARANG*D.HARGA_BARANG) AS [SUBTOTAL] FROM DETAIL_NOTA D LEFT JOIN BARANG B ON D.KD_BARANG=B.KODE_BARANG LEFT JOIN NOTA N ON D.KD_NOTA=N.NO_NOTA

26.

SELECT * FROM NOTA WHERE TGL_NOTA BETWEEN '2019-03-05' AND '2019-03-10'

27.

SELECT N.KD_KASIR, SUM(D.JUMLAH_BARANG*D.HARGA_BARANG) AS [TOTAL_UANG] FROM NOTA N JOIN DETAIL_NOTA D ON N.NO_NOTA=D.KD_NOTA

GROUP BY N.KD_KASIR

28.

SELECT K.KD_KASIR, K.NAMA_KASIR, COUNT(N.KD_KASIR) AS [JML_TRANSAKSI], (COUNT(N.NO_NOTA)*250) AS [BONUS] FROM KASIR K LEFT JOIN NOTA N ON K.KD_KASIR=N.KD_KASIR GROUP BY K.KD_KASIR, K.NAMA_KASIR

29.

SELECT N.NO_NOTA, N.TGL_NOTA, N.KD_KASIR, K.NAMA_KASIR, N.KD_PELANGGAN, P.NAMA_PELANGGAN, D.KD_BARANG, B.NAMA_BARANG, D.JUMLAH_BARANG, D.HARGA_BARANG,

(D.JUMLAH_BARANG*D.HARGA_BARANG) AS [SUBTOTAL] FROM NOTA N LEFT JOIN KASIR K ON N.KD_KASIR=K.KD_KASIR LEFT JOIN PELANGGAN P ON N.KD_PELANGGAN=P.KD_PELANGGAN LEFT JOIN DETAIL_NOTA D ON N.NO_NOTA=D.KD_NOTA LEFT JOIN BARANG B ON D.KD_BARANG=B.KODE_BARANG GROUP BY N.NO_NOTA, N.TGL_NOTA, N.KD_KASIR, K.NAMA_KASIR, N.KD_PELANGGAN, P.NAMA_PELANGGAN, D.KD_BARANG, B.NAMA_BARANG, D.JUMLAH_BARANG, D.HARGA_BARANG

30.

SELECT B.KODE_BARANG, B.NAMA_BARANG, B.HARGA_SATUAN, SUM(D.JUMLAH_BARANG) AS [TERJUAL],

(B.STOK-SUM(D.JUMLAH_BARANG)) AS [TERSEDIA] FROM BARANG B LEFT JOIN DETAIL_NOTA D ON B.KODE_BARANG=D.KD_BARANG GROUP BY B.KODE_BARANG, B.NAMA_BARANG, B.HARGA_SATUAN, B.STOK

SELECT * FROM BARANG