A. DML(memanipulasi data)data manifulation language.
sintak
insert (untuk menginputkan data)
1.mysql> insert into mahasiswa values('12345','zaki','jl.tgh.al-khalidi');
2.mysql> insert into mahasiswa values
-> ('12346','azhari','Kr.tapen'),
-> ('12347','kasino','kr.jasi');
select (untuk menampilkan isi table)
1. select * from mahasiswa;
2. mysql> select nama from mahasiswa;
+--------+
| nama |
+--------+
| zaki |
| azhari |
| kasino |
+--------+
3. select + where kondisi.
- mysql> select * from mahasiswa where nama='zaki';
+-------+------+-------------------+
| nim | nama | alamat |
+-------+------+-------------------+
| 12345 | zaki | jl.tgh.al-khalidi |
+-------+------+-------------------+
- mysql> select nama from mahasiswa where nama='zaki';
+------+
| nama |
+------+
| zaki |
+------+
- mysql> select nim,alamat from mahasiswa where nim=12345;
+-------+-------------------+
| nim | alamat |
+-------+-------------------+
| 12345 | jl.tgh.al-khalidi |
+-------+-------------------+
3. select having kondisi
4. select group by kondisi
5. select order by kondisi
update (memperbarui/mengubah)
1. update + set
mysql> update mahasiswa
-> set nama='muhammad'(ket=namabaru) where nama='kasino';
delete (menghapus)
1. select + where kondis
mysql> delete from mahasiswa where nim=12347;
B. Sintak kampus yang pertemuan ketiga
mysql> use kampusy;
Database changed
mysql> show tables;
+-------------------+
| Tables_in_kampusy |
+-------------------+
| dosen |
| mahasiswa |
| mk |
| nilai |
+-------------------+
4 rows in set (0.00 sec)
mysql> desc mahasiswa;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| nim | int(5) | NO | PRI | NULL | |
| nama | char(30) | YES | | NULL | |
| alamat | varchar(30) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.08 sec)
mysql> insert into mahasiswa values('12345','zaki','jl.tgh.al-khalidi');
Query OK, 1 row affected (0.07 sec)
mysql> desc mahasiswa;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| nim | int(5) | NO | PRI | NULL | |
| nama | char(30) | YES | | NULL | |
| alamat | varchar(30) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
mysql> insert into mahasiswa values
-> ('12346','azhari','Kr.tapen'),
-> ('12347','kasino','kr.jasi');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from mahasiswa;
+-------+--------+-------------------+
| nim | nama | alamat |
+-------+--------+-------------------+
| 12345 | zaki | jl.tgh.al-khalidi |
| 12346 | azhari | Kr.tapen |
| 12347 | kasino | kr.jasi |
+-------+--------+-------------------+
3 rows in set (0.00 sec)
mysql> select nama from mahasiswa;
+--------+
| nama |
+--------+
| zaki |
| azhari |
| kasino |
+--------+
3 rows in set (0.00 sec)
mysql> select * from mahasiswa where nama='zaki';
+-------+------+-------------------+
| nim | nama | alamat |
+-------+------+-------------------+
| 12345 | zaki | jl.tgh.al-khalidi |
+-------+------+-------------------+
1 row in set (0.01 sec)
mysql> select nama from mahasiswa;
+--------+
| nama |
+--------+
| zaki |
| azhari |
| kasino |
+--------+
3 rows in set (0.00 sec)
mysql> select nama from mahasiswa where nama='zaki';
+------+
| nama |
+------+
| zaki |
+------+
1 row in set (0.00 sec)
mysql> select nim,alamat from mahasiswa where nim=12345;
+-------+-------------------+
| nim | alamat |
+-------+-------------------+
| 12345 | jl.tgh.al-khalidi |
+-------+-------------------+
1 row in set (0.00 sec)
mysql> show tables;
+-------------------+
| Tables_in_kampusy |
+-------------------+
| dosen |
| mahasiswa |
| mk |
| nilai |
+-------------------+
4 rows in set (0.00 sec)
mysql> desc dosen;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| nip | int(5) | NO | PRI | 0 | |
| nama | char(30) | YES | | NULL | |
| alamat | varchar(30) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.04 sec)
mysql> insert into dosen values
-> ('12345','fikri','mataram');
Query OK, 1 row affected (0.04 sec)
mysql> insert into dosen values
-> ('12346','edi','sumbawa'),
-> ('12347','zaki','lombok');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from dosen;
+-------+-------+---------+
| nip | nama | alamat |
+-------+-------+---------+
| 12345 | fikri | mataram |
| 12346 | edi | sumbawa |
| 12347 | zaki | lombok |
+-------+-------+---------+
3 rows in set (0.00 sec)
mysql> update mahasiswa
-> set nama='muhammad' where nama='kasino';
Query OK, 1 row affected (0.09 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from mahasiswa;
+-------+----------+-------------------+
| nim | nama | alamat |
+-------+----------+-------------------+
| 12345 | zaki | jl.tgh.al-khalidi |
| 12346 | azhari | Kr.tapen |
| 12347 | muhammad | kr.jasi |
+-------+----------+-------------------+
3 rows in set (0.00 sec)
mysql> update mahasiswa
-> set nim=12348 where nim=12345;
Query OK, 1 row affected (0.08 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from mahasiswa;
+-------+----------+-------------------+
| nim | nama | alamat |
+-------+----------+-------------------+
| 12346 | azhari | Kr.tapen |
| 12347 | muhammad | kr.jasi |
| 12348 | zaki | jl.tgh.al-khalidi |
+-------+----------+-------------------+
3 rows in set (0.00 sec)
mysql> delete from mahasiswa where nim=12347;
Query OK, 1 row affected (0.05 sec)
mysql> select * from mahasiswa;
+-------+--------+-------------------+
| nim | nama | alamat |
+-------+--------+-------------------+
| 12346 | azhari | Kr.tapen |
| 12348 | zaki | jl.tgh.al-khalidi |
+-------+--------+-------------------+
2 rows in set (0.00 sec)