Вы находитесь на странице: 1из 3




Yitno Pambudi
Tugas
1. Query 1
create table konsumen
(ktp varchar (16) primary key not null,
nama varchar (50) not null,
alamat varchar (50) not null,
nomer_telepon varchar (12) not null)

create table kasir


(id varchar (5) primary key not null,
nama varchar (50) not null)

create table barang


(id_barang varchar (5) primary key not null,
nama_barang varchar (50) not null,
harga_barang int not null)

exec sp_rename 'kasir.nama', 'nama_kasir'

create table transaksi


(ktp varchar (16) primary key not null,
nama varchar (50) not null,
nama_kasir varchar (50) not null,
nama_barang varchar (50) not null,
harga_barang int not null)

insert into konsumen values


('3579030504000001', 'Arya', 'Karangharjo', '082284506762'),
('3579030504000002', 'Ani', 'Tegaldlimo', '082284506755'),
('3579030504000003', 'Budi', 'Kalirejo', '082284506798'),
('3579030504000004', 'Abdul', 'Bumiharjo', '082284506709'),
('3579030504000005', 'Jono', 'Krajan', '082284506712')

insert into kasir values


('00001', 'Haryo'),
('00010', 'Krisna'),
('00020', 'Harto')

insert into barang values


('G0001', 'DVD', 15000),
('H0002', 'Hardisk', 550000),
('I0023', 'Monitor', 2000000),
('Q0011', 'CD', 10000),
('A0098', 'Mouse', 15000),
('K0008', 'Keyboard', 90000),
('L0076', 'CPU', 5000000),
('P0054', 'Flashdisk', 45000),
('PO067', 'Sim Card', 5000),
('UY001', 'VGA', 3000000)

insert into transaksi values


('3579030504000001', 'Arya', 'Krisna', 'CPU', 5000000),
('3579030504000003', 'Budi', 'Krisna', 'Mouse', 15000),
('3579030504000004', 'Abdul', 'Krisna', 'VGA', 3000000)

2. View 1
create view pelanggan
as
select ktp, nama from konsumen
Tampilan Hasil

3. View 2
create view dagangan
as
select nama_barang, harga_barang from Barang
Tampilan Hasil

4. Subquery 1
select nama_barang, harga_barang from barang as a where not exists
(select nama_barang, harga_barang from transaksi as b where a.nama_barang =
b.nama_barang)
Tampilan Hasil

5. Subquery 2
select ktp, nama, alamat from konsumen as a where exists
(select ktp, nama from transaksi as b where a.nama = b.nama)
Tampilan Hasil