MySQL Console - Dasar I

3
MySQL console DDL (create, alter, drop) DML (select, insert, update, delete) 1. Buat database perpus 2. Buat tabel buku - kode_buku char(5) - nama_buku varchar(30) - judul varchar(30) 3. Buat tabel anggota - id varchar(6) primary key - nama varchar(30) - alamat varchar(20) - kelas varchar(10) 4. Tambahkan field pengarang di tabel buku dengan tipe data varchar(30) 5. Ubah judul di tabel buku menjadi judul_buku dgn tipe data yang sama 6. Ubah tipe data nama di tabel anggota menjadi char(35) 7. Isi 1 data pada tabel anggota 8. Tampilkan isi data 9. Tampilkan tabel dan descriptions yang ada di database perpus ========================================================================= == Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 5.5.20-log MySQL Community Server (GPL) Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database perpus; Query OK, 1 row affected (0.00 sec)

Transcript of MySQL Console - Dasar I

Page 1: MySQL Console - Dasar I

MySQL consoleDDL (create, alter, drop)DML (select, insert, update, delete)

1. Buat database perpus2. Buat tabel buku

- kode_buku char(5)- nama_buku varchar(30)- judul varchar(30)

3. Buat tabel anggota- id varchar(6) primary key- nama varchar(30)- alamat varchar(20)- kelas varchar(10)

4. Tambahkan field pengarang di tabel buku dengan tipe data varchar(30)5. Ubah judul di tabel buku menjadi judul_buku dgn tipe data yang sama6. Ubah tipe data nama di tabel anggota menjadi char(35)7. Isi 1 data pada tabel anggota8. Tampilkan isi data9. Tampilkan tabel dan descriptions yang ada di database perpus

===========================================================================Enter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 12Server version: 5.5.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database perpus;Query OK, 1 row affected (0.00 sec)

mysql> use perpus;Database changedmysql> create table buku (kode_buku char(5), nama_buku varchar(30), judul varchar(30));Query OK, 0 rows affected (0.13 sec)

mysql> create table anggota (id varchar(6), nama varchar(30), alamat varchar(20), kelas varchar(10));Query OK, 0 rows affected (0.00 sec)

Page 2: MySQL Console - Dasar I

mysql> alter table buku add pengarang varchar(30);Query OK, 0 rows affected (0.01 sec)Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table buku change judul judul_buku varchar(30);Query OK, 0 rows affected (0.08 sec)Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table anggota modify nama char(35);Query OK, 0 rows affected (0.01 sec)Records: 0 Duplicates: 0 Warnings: 0

mysql> insert into anggota values('080194','Yobby','Purnama','12.2F.30');Query OK, 1 row affected (0.05 sec)

mysql> select *from anggota;+--------+-------+---------+----------+| id | nama | alamat | kelas |+--------+-------+---------+----------+| 080194 | Yobby | Purnama | 12.2F.30 |+--------+-------+---------+----------+1 row in set (0.00 sec)

mysql> show tables;+------------------+| Tables_in_perpus |+------------------+| anggota || buku |+------------------+2 rows in set (0.00 sec)

mysql> alter table anggota add primary key(id);Query OK, 1 row affected (0.08 sec)Records: 1 Duplicates: 0 Warnings: 0

mysql> desc anggota;+--------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+--------+-------------+------+-----+---------+-------+| id | varchar(6) | NO | PRI | | || nama | char(35) | YES | | NULL | || alamat | varchar(20) | YES | | NULL | || kelas | varchar(10) | YES | | NULL | |+--------+-------------+------+-----+---------+-------+4 rows in set (0.05 sec)

mysql> desc buku;+------------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+------------+-------------+------+-----+---------+-------+| kode_buku | char(5) | YES | | NULL | || nama_buku | varchar(30) | YES | | NULL | || judul_buku | varchar(30) | YES | | NULL | |

Page 3: MySQL Console - Dasar I

| pengarang | varchar(30) | YES | | NULL | |+------------+-------------+------+-----+---------+-------+4 rows in set (0.02 sec)

mysql>