MATERI LATIHAN DATABASE MYSQL


MATERI LATIHAN DATABASE MYSQL

Mysql>Show databases;
Mysql>create database guru;
Mysql>use guru;

Mysql>Create table Biodata_guru
          .>(nip int(9) not null,
          .>Nama_guru varchar(25) not null,
          .>pendidikan varchar(15) not null,
          .>kode_sekolah int(2) not null,
          .>kode_pljr int(2) not null,
          .>kode_kec int(2) not null,
.>Primary key (nip)
          .>);
Desc biodata_guru;
Mysql>insert into biodata_guru values
          .> (‘132321411’,’Dr. Ali’,’Sarjana’,’91’,’62’,’83’),
          .> (‘132765987’,’Ir. Mae’,’Sarjana’,’88’,’77’,’42’),
          .> (‘132878981’,’Insyah. SE’,’Sarjana’,’55’,’11’,’32’),
          .> (‘132321412’,’Drs. Yacob’,’Sarjana’,’91’,’62’,’83’),
          .> (‘132765988’,’Ir. adam’,’Sarjana’,’81’,’71’,’44’),
          .> (‘132878980’,’baktiar. SE’,’Sarjana’,’55’,’17’,’32’);

select * from biodata_guru;
Mysql>Create table pelajaran
          .>(kode_pljr int(2) not null,
          .>Nama_pljr varchar(25) not null,
          .>jum_jam char(2) not null,
          .>Primary key (kode_pljr)
          .>);
Desc Pelajaran;
Mysql>insert into pelajaran values
.> (‘62’,Matematika’,’14’),
.> (‘71’,’fisika’,’11’),
.> (‘99’,’ketrampilan’,’12’);

Mysql>Create table sekolah
        .>(kode_sekolah int(2) not null,
        .>Nama_sekolah varchar(25) not null,
        .>alamat_sekolah varchar(50) not null,
        .>Primary key (kode_sekolah)
        .>);

Mysql>Create table kecamatan
        .>(kode_kec int(2) not null,
        .>Nama_kec varchar(25) not null,
        .>Primary key (kode_kec)
        .>);


FUNGSI-FUNGSI PERINTAH MYSQL

1.     Mysql>drop database simguru;
Menghapus nama database simguru

2.     Mysql>use simguru;
Mengaktifkan database simguru

3.     Mysql>drop table biodata_guru;
Menghapus tabel dengan nama biodata_guru

4.     Mysql>rename table biodata_guru to penyakit;
Merubah nama tabel biodata_guru  menjadi tabel penyakit

5.     Mysql>alter table biodata_guru add pangkat varchar(15);
Menambah field pangkat dengan type varchar ukuran 15 pada tabel biodata_guru

6.     M Mysql>alter table biodata_guru
    >add primary key (nip);
          Mengubah tabel biodata_guru dan membuat kunci utama pada tabel biodata_guru yaitu nip.

7.     Mysql>alter table biodata_guru  drop alamat;
Menghapus kolom alamat pada tabel biodata_guru

8.     Mysql>delete from biodata_guru;
Menghapus data pada tabel biodata_guru

9.     Mysql>delete from biodata_guru
>where no=’5’;
          Menghapus data pada tabel biodata_guru dengan no 5
10.                        Mysql>select  biodata_guru.nama_guru,
>nama_pljr.pelajaran
>from biodata_guru,pelajaran;

Share this

Related Posts

Previous
Next Post »