• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Cat database
 

Cat database

on

  • 200 views

 

Statistics

Views

Total Views
200
Views on SlideShare
200
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Cat database Cat database Document Transcript

    • [root@koneksi ~]# service mysqld startStarting mysqld: [ OK ][root@koneksi ~]# mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 2Server version: 5.1.67 Source distributionCopyright (c) 2000, 2012, 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> show databases;+--------------------+| Database |+--------------------+| information_schema || appPegawai || coba || dbpegawai || mysql || test |+--------------------+6 rows in set (0.04 sec)mysql> create database pbd;Query OK, 1 row affected (0.00 sec)mysql> use pbd;Database changedmysql> show tables;Empty set (0.00 sec)mysql> create table siswa( -> id int primary key, -> nama varchar(30), -> alamat text, -> jk char(1));Query OK, 0 rows affected (0.08 sec)mysql> show tables;+---------------+| Tables_in_pbd |+---------------+| siswa |+---------------+1 row in set (0.00 sec)mysql> desc siswa;+--------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+--------+-------------+------+-----+---------+-------+| id | int(11) | NO | PRI | NULL | || nama | varchar(30) | YES | | NULL | || alamat | text | YES | | NULL | || jk | char(1) | YES | | NULL | |+--------+-------------+------+-----+---------+-------+4 rows in set (0.02 sec)mysql> insert into siswa(id, nama, alamat, jk)
    • -> values(1, Sapari Andi, Mampang, L);Query OK, 1 row affected (0.00 sec)mysql> insert into siswa(id, nama, alamat, jk)values(1, Sapari Andi,Mampang, L) -> ;ERROR 1062 (23000): Duplicate entry 1 for key PRIMARYmysql> insert into siswa(id, nama, alamat, jk) -> values (2, Dede Hidayat);ERROR 1136 (21S01): Column count doesnt match value count at row 1mysql> insert into siswa(id, nama) values (2, Dede Hidayat);Query OK, 1 row affected (0.00 sec)mysql> show tables;+---------------+| Tables_in_pbd |+---------------+| siswa |+---------------+1 row in set (0.00 sec)mysql> desc siswa;+--------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+--------+-------------+------+-----+---------+-------+| id | int(11) | NO | PRI | NULL | || nama | varchar(30) | YES | | NULL | || alamat | text | YES | | NULL | || jk | char(1) | YES | | NULL | |+--------+-------------+------+-----+---------+-------+4 rows in set (0.00 sec)mysql> select * from siswa;+----+--------------+---------+------+| id | nama | alamat | jk |+----+--------------+---------+------+| 1 | Sapari Andi | Mampang | L || 2 | Dede Hidayat | NULL | NULL |+----+--------------+---------+------+2 rows in set (0.00 sec)mysql> insert into siswa values(3, Heni Lestari, Kalibata, P);Query OK, 1 row affected (0.00 sec)mysql> select nama from siswa;+--------------+| nama |+--------------+| Sapari Andi || Dede Hidayat || Heni Lestari |+--------------+3 rows in set (0.00 sec)mysql> select * from siswa;+----+--------------+----------+------+| id | nama | alamat | jk |+----+--------------+----------+------+| 1 | Sapari Andi | Mampang | L || 2 | Dede Hidayat | NULL | NULL || 3 | Heni Lestari | Kalibata | P |+----+--------------+----------+------+3 rows in set (0.00 sec)
    • mysql> update siswa set alamat=Ciamis where id=2;Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from siswa;+----+--------------+----------+------+| id | nama | alamat | jk |+----+--------------+----------+------+| 1 | Sapari Andi | Mampang | L || 2 | Dede Hidayat | Ciamis | NULL || 3 | Heni Lestari | Kalibata | P |+----+--------------+----------+------+3 rows in set (0.00 sec)mysql> update siswa set jk=L where id=2;Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from siswa;+----+--------------+----------+------+| id | nama | alamat | jk |+----+--------------+----------+------+| 1 | Sapari Andi | Mampang | L || 2 | Dede Hidayat | Ciamis | L || 3 | Heni Lestari | Kalibata | P |+----+--------------+----------+------+3 rows in set (0.00 sec)mysql> update siswa set jk=1 where jk=P;Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from siswa;+----+--------------+----------+------+| id | nama | alamat | jk |+----+--------------+----------+------+| 1 | Sapari Andi | Mampang | L || 2 | Dede Hidayat | Ciamis | L || 3 | Heni Lestari | Kalibata | 1 |+----+--------------+----------+------+3 rows in set (0.00 sec)mysql> update siswa set jk=0 where jk=L;Query OK, 2 rows affected (0.00 sec)Rows matched: 2 Changed: 2 Warnings: 0mysql> select * from siswa;+----+--------------+----------+------+| id | nama | alamat | jk |+----+--------------+----------+------+| 1 | Sapari Andi | Mampang | 0 || 2 | Dede Hidayat | Ciamis | 0 || 3 | Heni Lestari | Kalibata | 1 |+----+--------------+----------+------+3 rows in set (0.00 sec)mysql> delete from siswa where id=2;Query OK, 1 row affected (0.00 sec)mysql> select * from siswa;+----+--------------+----------+------+| id | nama | alamat | jk |+----+--------------+----------+------+| 1 | Sapari Andi | Mampang | 0 |
    • | 3 | Heni Lestari | Kalibata | 1 |+----+--------------+----------+------+2 rows in set (0.00 sec)mysql> select * from siswa order by alamat;+----+--------------+----------+------+| id | nama | alamat | jk |+----+--------------+----------+------+| 3 | Heni Lestari | Kalibata | 1 || 1 | Sapari Andi | Mampang | 0 |+----+--------------+----------+------+2 rows in set (0.00 sec)mysql> create table guru( -> id int primary key auto_increment, -> nama varchar(30), -> alamat text, -> gaji double);Query OK, 0 rows affected (0.06 sec)mysql> insert into guru(nama,alamat,gaji) -> values(Karim Santoso,Pancoran,8000000);Query OK, 1 row affected (0.00 sec)mysql> select * from guru;+----+---------------+----------+---------+| id | nama | alamat | gaji |+----+---------------+----------+---------+| 1 | Karim Santoso | Pancoran | 8000000 |+----+---------------+----------+---------+1 row in set (0.00 sec)mysql> desc guru;+--------+-------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+--------+-------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || nama | varchar(30) | YES | | NULL | || alamat | text | YES | | NULL | || gaji | double | YES | | NULL | |+--------+-------------+------+-----+---------+----------------+4 rows in set (0.00 sec)mysql> create table mahasiswa( -> npm int primary key auto_increment, -> nama varchar(30), -> ;ERROR 1064 (42000): You have an error in your SQL syntax; check the manual thatcorresponds to your MySQL server version for the right syntax to use near atline 3mysql> show tables;+---------------+| Tables_in_pbd |+---------------+| guru || siswa |+---------------+2 rows in set (0.00 sec)mysql> create table mahasiswa( -> npm int primary key auto_increment, -> nama varchar(30));Query OK, 0 rows affected (0.06 sec)
    • mysql> create table matakuliah( -> kodemk int primary key, -> mk varchar(30));Query OK, 0 rows affected (0.06 sec)mysql> create table krs( -> npm int, -> ta int, -> semester char(1), -> kodemk int);Query OK, 0 rows affected (0.07 sec)mysql> show tables;+---------------+| Tables_in_pbd |+---------------+| guru || krs || mahasiswa || matakuliah || siswa |+---------------+5 rows in set (0.00 sec)mysql> desc pbd;ERROR 1146 (42S02): Table pbd.pbd doesnt existmysql> show tables;+---------------+| Tables_in_pbd |+---------------+| guru || krs || mahasiswa || matakuliah || siswa |+---------------+5 rows in set (0.00 sec)mysql> desc krs;+----------+---------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+----------+---------+------+-----+---------+-------+| npm | int(11) | YES | | NULL | || ta | int(11) | YES | | NULL | || semester | char(1) | YES | | NULL | || kodemk | int(11) | YES | | NULL | |+----------+---------+------+-----+---------+-------+4 rows in set (0.00 sec)mysql> desc mahasiswa;+-------+-------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+-------------+------+-----+---------+----------------+| npm | int(11) | NO | PRI | NULL | auto_increment || nama | varchar(30) | YES | | NULL | |+-------+-------------+------+-----+---------+----------------+2 rows in set (0.00 sec)mysql> desc matakuliah;+--------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+--------+-------------+------+-----+---------+-------+| kodemk | int(11) | NO | PRI | NULL | || mk | varchar(30) | YES | | NULL | |
    • +--------+-------------+------+-----+---------+-------+2 rows in set (0.00 sec)mysql>