boedak kubu

Tuesday, December 6, 2011

command sql di mysql client

Enter password:******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database hasim;
Query OK, 1 row affected (0.03 sec)

mysql> use hasim;
Database changed
mysql> create table lung (kd_plg int(3) not null primary key,nama_plg varchar(15
),alamat varchar(25),daerah_asal varchar(15));
Query OK, 0 rows affected (0.08 sec)

mysql> insert into lung values (001,'bayu','delima','pekanbaru'),(002,'dede','jl
.damai','tembilahan'),(003,'sobirin','purwodadi','bagan'),(004,'iful','smp.tiga'
,'padang');
Query OK, 4 rows affected (0.03 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> select * from lung where daerah_asal='bagan';
+--------+----------+-----------+-------------+
| kd_plg | nama_plg | alamat    | daerah_asal |
+--------+----------+-----------+-------------+
|      3 | sobirin  | purwodadi | bagan       |
+--------+----------+-----------+-------------+
1 row in set (0.06 sec)

mysql> delete from lung where nama_plg='iful';
Query OK, 1 row affected (0.00 sec)

mysql> update lung set daerah_asal='bagan api' where nama_plg='sobirin';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> alter table lung add hoby varchar(10);
Query OK, 3 rows affected (0.13 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> update lung set hoby='menyanyi' where nama_plg='bayu';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update lung set hoby='menyanyi' where nama_plg='dede';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update lung set hoby='memancing' where nama_plg='sobirin';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from lung where hoby='menyanyi';
+--------+----------+----------+-------------+----------+
| kd_plg | nama_plg | alamat   | daerah_asal | hoby     |
+--------+----------+----------+-------------+----------+
|      1 | bayu     | delima   | pekanbaru   | menyanyi |
|      2 | dede     | jl.damai | tembilahan  | menyanyi |
+--------+----------+----------+-------------+----------+
2 rows in set (0.00 sec)

mysql> desc lung;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| kd_plg      | int(3)      | NO   | PRI | NULL    |       |
| nama_plg    | varchar(15) | YES  |     | NULL    |       |
| alamat      | varchar(25) | YES  |     | NULL    |       |
| daerah_asal | varchar(15) | YES  |     | NULL    |       |
| hoby        | varchar(10) | YES  |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.05 sec)

mysql> delete from lung where hoby='memancing';
Query OK, 1 row affected (0.00 sec)

mysql> drop table lung;
Query OK, 0 rows affected (0.02 sec)

mysql> drop database hasim;
Query OK, 0 rows affected (0.01 sec)

mysql>

0 comments: