Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

3 rows in set (0.

00 sec)
mysql> select *
-> FROM latih1;
+-------+-----------+
| nama | alamat
|
+-------+-----------+
| Dedi | Bandung |
| Adit | Margahayu |
| Adit | Cijerah |
| Kemal | Tasik
|
+-------+-----------+
4 rows in set (0.00 sec)
mysql> select alamat
-> from latih1
-> ORDER BY nama;
+-----------+
| alamat
|
+-----------+
| Margahayu |
| Cijerah |
| Bandung |
| Tasik
|
+-----------+
4 rows in set (0.01 sec)
mysql> select *
-> from latih1
-> ORDER BY nama;
+-------+-----------+
| nama | alamat
|
+-------+-----------+
| Adit | Margahayu |
| Adit | Cijerah |
| Dedi | Bandung |
| Kemal | Tasik
|
+-------+-----------+
4 rows in set (0.00 sec)
mysql> select *
-> from latih1
-> ORDER BY nama DESC;
+-------+-----------+
| nama | alamat
|
+-------+-----------+
| Kemal | Tasik
|
| Dedi | Bandung |
| Adit | Margahayu |
| Adit | Cijerah |
+-------+-----------+
4 rows in set (0.00 sec)
mysql> create table latih2(nama char(30),tempat_lahir char(30),tanggal date);
Query OK, 0 rows affected (0.06 sec)
mysql> INSERT INTO latih2
-> VALUES ("Deni Sanjaya","Bandung",1989-01-10);
ERROR 1292 (22007): Incorrect date value: '1978' for column 'tanggal' at row 1
mysql> VALUES ("Deni Sanjaya","Bandung","1989-01-10");

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'VALUE
S ("Deni Sanjaya","Bandung","1989-01-10")' at line 1
mysql> VALUES ("Deni Sanjaya","Bandung",'1989-01-10');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'VALUE
S ("Deni Sanjaya","Bandung",'1989-01-10')' at line 1
mysql> VALUES ("Deni Sanjaya","Bandung",'1989-01-10');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'VALUE
S ("Deni Sanjaya","Bandung",'1989-01-10')' at line 1
mysql> show tables;
+-------------------+
| Tables_in_latihan |
+-------------------+
| latih1
|
| latih2
|
| latihl
|
| tabel
|
+-------------------+
4 rows in set (0.01 sec)
mysql> INSERT INTO latih2
-> VALUES ("Deni Sanjaya","Bandung",1989-01-10);
ERROR 1292 (22007): Incorrect date value: '1978' for column 'tanggal' at row 1
mysql> VALUES ("Deni Sanjaya","Bandung",'1989-01-10');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'VALUE
S ("Deni Sanjaya","Bandung",'1989-01-10')' at line 1
mysql> INSERT INTO latih2
-> VALUES ("Deni Sanjaya","Bandung",'1989-01-10');
Query OK, 1 row affected (0.05 sec)
mysql> select *
-> from latih2;
+--------------+--------------+------------+
| nama
| tempat_lahir | tanggal
|
+--------------+--------------+------------+
| Deni Sanjaya | Bandung
| 1989-01-10 |
+--------------+--------------+------------+
1 row in set (0.00 sec)
mysql> INSERT INTO latih2
-> VALUES ("Dedi Damhudi","Jakarta",'1989-01-10');
Query OK, 1 row affected (0.03 sec)
mysql> select *
-> from latih2;
+--------------+--------------+------------+
| nama
| tempat_lahir | tanggal
|
+--------------+--------------+------------+
| Deni Sanjaya | Bandung
| 1989-01-10 |
| Dedi Damhudi | Jakarta
| 1989-01-10 |
+--------------+--------------+------------+
2 rows in set (0.00 sec)
mysql> select nama,tanggal, CURDATE(),
-> AS umur
-> from latih2;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that

corresponds to your MySQL server version for the right syntax to use near 'AS um
ur
from latih2' at line 2
mysql> select nama,tanggal, CURDATE(),
-> (YEAR(CURDATE())-YEAR(Tanggal))
-> AS umur
-> from latih2;
+--------------+------------+------------+------+
| nama
| tanggal
| CURDATE() | umur |
+--------------+------------+------------+------+
| Deni Sanjaya | 1989-01-10 | 2012-05-30 | 23 |
| Dedi Damhudi | 1989-01-10 | 2012-05-30 | 23 |
+--------------+------------+------------+------+
2 rows in set (0.01 sec)
mysql> INSERT INTO latih2
-> VALUES ("Amir Syamsudin","Cimahi",'1991-31-12');
ERROR 1292 (22007): Incorrect date value: '1991-31-12' for column 'tanggal' at r
ow 1
mysql> INSERT INTO latih2
-> VALUES ("Amir Syamsudin","Cimahi",'1991-03-12');
Query OK, 1 row affected (0.02 sec)
mysql> select *
-> from latih2;
+----------------+--------------+------------+
| nama
| tempat_lahir | tanggal
|
+----------------+--------------+------------+
| Deni Sanjaya | Bandung
| 1989-01-10 |
| Dedi Damhudi | Jakarta
| 1989-01-10 |
| Amir Syamsudin | Cimahi
| 1991-03-12 |
+----------------+--------------+------------+
3 rows in set (0.00 sec)
mysql> select nama,tanggal, CURDATE(),
-> (YEAR(CURDATE())-YEAR(Tanggal))
-> AS umur
-> from latih2;
+----------------+------------+------------+------+
| nama
| tanggal
| CURDATE() | umur |
+----------------+------------+------------+------+
| Deni Sanjaya | 1989-01-10 | 2012-05-30 | 23 |
| Dedi Damhudi | 1989-01-10 | 2012-05-30 | 23 |
| Amir Syamsudin | 1991-03-12 | 2012-05-30 | 21 |
+----------------+------------+------------+------+
3 rows in set (0.00 sec)
mysql> select nama,tanggal, last_day(tgl),
-> AS akhir
-> from latih2;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'AS ak
hir
from latih2' at line 2
mysql> select nama,tanggal,Last_Day(tgl),
-> AS akhir
-> from latih2;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'AS ak
hir

from latih2' at line 2


mysql> select nama,tanggal, last_day(tanggal),
-> AS akhir
-> from latih2;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'AS ak
hir
from latih2' at line 2
mysql> select nama,tanggal, CURDATE(),
-> (MONTH(CURDATE())-MONTH(Tanggal))
-> AS umur
-> from latih2;
+----------------+------------+------------+------+
| nama
| tanggal
| CURDATE() | umur |
+----------------+------------+------------+------+
| Deni Sanjaya | 1989-01-10 | 2012-05-30 |
4 |
| Dedi Damhudi | 1989-01-10 | 2012-05-30 |
4 |
| Amir Syamsudin | 1991-03-12 | 2012-05-30 |
2 |
+----------------+------------+------------+------+
3 rows in set (0.01 sec)
mysql> update latih2
-> set nama='Bobi Kuncoro'
-> where nama='Dedi Damhudi';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select *
-> from latih2;
+----------------+--------------+------------+
| nama
| tempat_lahir | tanggal
|
+----------------+--------------+------------+
| Deni Sanjaya | Bandung
| 1989-01-10 |
| Bobi Kuncoro | Jakarta
| 1989-01-10 |
| Amir Syamsudin | Cimahi
| 1991-03-12 |
+----------------+--------------+------------+
3 rows in set (0.00 sec)
mysql> delete from latih2
-> where nama='Deni Sanjaya';
Query OK, 1 row affected (0.02 sec)
mysql> alter table latih2
-> add Hobi Char;
Query OK, 2 rows affected (0.30 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select *
-> from latih2;
+----------------+--------------+------------+------+
| nama
| tempat_lahir | tanggal
| Hobi |
+----------------+--------------+------------+------+
| Bobi Kuncoro | Jakarta
| 1989-01-10 | NULL |
| Amir Syamsudin | Cimahi
| 1991-03-12 | NULL |
+----------------+--------------+------------+------+
2 rows in set (0.00 sec)
mysql> set hobi
-> set Hobi='Baca'
-> where nama='Bobi Kuncoro';

ERROR 1193 (HY000): Unknown system variable 'hobi'


mysql> set Hobi='Baca'
-> where nama='Bobi Kuncoro';
ERROR 1193 (HY000): Unknown system variable 'Hobi'
mysql> set Hobi='Baca'
-> update latih2
-> set Hobi='Baca';
ERROR 1193 (HY000): Unknown system variable 'Hobi'
mysql> update latih2
-> set Hobi="Baca";
ERROR 1406 (22001): Data too long for column 'Hobi' at row 1
mysql> alter table latih2
-> add Hobi Char(30);
ERROR 1060 (42S21): Duplicate column name 'Hobi'
mysql> select *
-> from latih2;
+----------------+--------------+------------+------+
| nama
| tempat_lahir | tanggal
| Hobi |
+----------------+--------------+------------+------+
| Bobi Kuncoro | Jakarta
| 1989-01-10 | NULL |
| Amir Syamsudin | Cimahi
| 1991-03-12 | NULL |
+----------------+--------------+------------+------+
2 rows in set (0.00 sec)
mysql> update latih2
-> set Hobi="Baca";
ERROR 1406 (22001): Data too long for column 'Hobi' at row 1
mysql> modify hobi char(30);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'modif
y hobi char(30)' at line 1
mysql> modify Hobi char(30);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'modif
y Hobi char(30)' at line 1
mysql> MODIFY Hobi char(30);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'MODIF
Y Hobi char(30)' at line 1
mysql> ALTER TABLE latih2
-> MODIFY Hobi Char(30);
Query OK, 2 rows affected (0.14 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> Update latih2
-> set Hobi="Baca";
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> select *
-> from latih2;
+----------------+--------------+------------+------+
| nama
| tempat_lahir | tanggal
| Hobi |
+----------------+--------------+------------+------+
| Bobi Kuncoro | Jakarta
| 1989-01-10 | Baca |
| Amir Syamsudin | Cimahi
| 1991-03-12 | Baca |
+----------------+--------------+------------+------+
2 rows in set (0.00 sec)
mysql>

You might also like