Sei sulla pagina 1di 9

I.

TUJUAN

Setelah melakukan praktikum ini, mahasiswa mampu menggunakan


perintah-perintah Data Manipulation Language(DML)

II. MATA KULIAH PENUNJANG

1. Tidak ada

III. ALAT DAN BAHAN

No. Nama Alat Spesifikasi Jumlah Satuan


dan Bahan
1. Komputer(PC) P-4 1 Unit
2. Printer Brother 1 Unit
3. Kertas A4 3 Lembar
4. Software MySQL Server 1 Paket
5.0

IV. LANGKAH KERJA

1. Jalankan program MS SQL Server 2005


2. Buat database SalesOrder
Coding : Create database SalesOrder;
3. Pada database tersebut, buat tabel Product dengan isi seperti
berikut(data pada Product_ID bertambah secara otomatis) :

Product Product Item Name Size Unit


ID Category Price
1 Women Long-sleeve jersey Large 39.95
dress
2 Boys Iron-Free Pleated Small 39.95
Pants
3 Men Striped long-sleeve Large 59.60
shirt
4 Girls Shoulder handbag 45.00
5 Women Continental skirt Medium 39.95
Coding :
create table Product
(
[Product ID] int identity(1,1) not null,
[Product Category] char(6),
[Item Name] varchar(40),
[size] char(10),
[Unit Price] decimal(5,2)
);
4. Masukkan data-data diatas pada tabel Product
Coding :
use SalesOrder;
go
insert into Product([Product Category],[Item Name],[Size],[Unit
Price])
values('Woman','Long-sleeve jersey dress','Large','39.95');
go
insert into Product
values('Boys','Iron-Free Pleated Pants','Small','39.95');
go
insert into Product
values ('Men','Striped long-sleeve shirt','large','59.60');
go
insert into Product([Product Category],[Item Name],[Size],[Unit
Price])
values('Girls','Shoulder handbag',' ','45.00');
go
insert into Product([Product Category],[Item Name],[Size],[Unit
Price])
values('Women','Continental skirt','Medium','39.95');
5. Pada database SalesOrder buat lagi tabel Employee dengan isi seperti
berikut (PRIMARY KEY Employee ID) :

Employee Employee
Title City Birth Date
ID Name
Sales
EMP-01 Nancy Davolio Seattle 1948-12-08
Representative
Vice President,
EMP-02 Andrew Fuller Tacoma 1952-02-19
Sales
Sales
EMP-03 Janet Leverling Kirkland 1963-08-30
Representative
Margaret Sales
EMP-04 Redmond 1957-09-19
Peacock Representative
Steven Sales
EMP-05 London 1955-03-04
Buchanan Representative
EMP-06 Michael SuyamaSales Manager London 1963-07-02
Sales
EMP-07 Robert King London 1960-05-29
Representative
Sales
EMP-08 Laura Callahan Seattle 1958-01-09
Representative
EMP-09 Anne Inside Sales London 1966-01-27
Dodsworth Coordinator

Coding :
create table employee
(
Employee_ID varchar(8) not null ,
[Employee name] varchar(20),
Title varchar(30),
City varchar(10),
[Birth Date] smalldatetime,
constraint Employee_ID PRIMARY KEY (employee_id)
);
6. Masukkan data-data diatas pada tabel Employee
Coding :
insert into employee(Employee_ID,[Employee Name],Title,City,
[Birth Date])
values('EMP-01','Nancy Davolio','Sales
Representative','Seattle','1948-12-08');
go
insert into employee(Employee_ID,[Employee Name],Title,City,
[Birth Date])
values('EMP-02','Andrew Fuller','Vice President,
Sales','Tacoma','1952-02-19');
go
insert into employee(Employee_ID,[Employee Name],Title,City,
[Birth Date])
values('EMP-03','Janet Leverling','Sales
Representative','Kirkland','1963-08-30');
go
insert into employee(Employee_ID,[Employee Name],Title,City,
[Birth Date])
values('EMP-04','Margaret Peacock','Sales
Representative','Redmond','1957-09-19');
go
insert into employee(Employee_ID,[Employee Name],Title,City,
[Birth Date])
values('EMP-05','Steven Buchanan','Sales
Representative','London','1955-03-04');
go
insert into employee(Employee_ID,[Employee Name],Title,City,
[Birth Date])
values('EMP-06','Michael Suyama','Sales Manager','London','1963-
07-02');
go
insert into employee(Employee_ID,[Employee Name],Title,City,
[Birth Date])
values('EMP-07','Robert King','Sales Representative','London','1960-
05-29');
go
insert into employee(Employee_ID,[Employee Name],Title,City,
[Birth Date])
values('EMP-08','Laura Callahan','Sales
Representative','Seattle','1958-01-09');
go
insert into employee(Employee_ID,[Employee Name],Title,City,
[Birth Date])
values('EMP-09','Anne Dodsworth','Inside Sales
Coordinator','London','1966-01-27');
7. Tampilkan seluruh kolom pada tabel Product
Coding : select * from Product

8. Tampilkan data pada kolom Product ID, Item Name, dan Unit Price
pada tabel Product
Coding :Select [Product ID],[Item Name],[Unit Price] from Product

9. Tampilkan seluruh kolom pada tabel product yang memiliki unit price
di atas 39.95
Coding : select * from product where [Unit Price] = '39.95';

10.Tampilkan kota yang berbeda pada tabel Employee


Coding : select distinct city from employee;
11.Pada tabel Employee, tampilkan seluruh kolom yang bertitle Sales
Representative dan diurut erdasrkan Employee Name secara
Ascending
Coding : select * from employee where title = 'Sales Representative'
order by [Employee Name] asc;

12.Pada Tabel Employee, tampilkan seluruh kolom yang bertitle Sales


Representative dan beralamat di kota London
Coding : select * from employee where title = 'Sales Representative'
and city = 'London';

13.Pada tabel Employee, tampilkan Employee yang lahir di atas tahun


1957. (Untuk mengambil tahun Birth Date, gunakan fungsi year())
Coding : select * from employee where year([birth date]) > '1957';
14.Pada tabel Employee, tampilkan Employee yang lahir diatas tahun
1950 dan di bawah tahun 1960
Coding : select * from employee where [birth date] between '1950'
and '1960';

15.Pada tabel Employee, tampilkan Employee yang memiliki usia diatas


50 tahun dan dibawah 55 tahun. (Untuk mengambil tanggal system
gunakan fungsi getdate())
Coding : select * from employee where year(getdate()) - year([birth
date]) > 50 and year(getdate()) - year([birth date]) < 55;

16.Pada tabel Employee, tampilkan seluruh kolom yang bertitle Sales


Representative atau beralamatkan di London
Coding : select * from employee where title = 'Sales Representative'
and city = 'London';

17.Pada tabel Employee, tampilkan seluruh kolom yang beralamat di


kota Seattle, Redmon, Tacoma, Kirkland
Coding : select * from employee where city
in('Seattle','Redmond','Tacoma','Kirkland');
18.Pada tabel Employee, tampilkan seluruh kolom yang memiliki huruf
awal nama “M”
Coding : select * from employee where [Employee Name] like'M%';

19.Pada tabel Employee, tampilkan seluruh kolom yang memiliki nama


antara Laura Callahan dan Robert King
Coding : select * from employee where [Employee Name] between
'Laura Callahan' and 'Robert King';

20.Dikarenakan Agen cabang di kota London ditutup, maka hapus data


tersebut
Coding : Delete from Employee where city = ‘London’

Potrebbero piacerti anche