Minggu, 26 Desember 2010

Membuat Database MySQL 2

mysql> create database JMB;

mysql> use JMB;
Database changed


//Membuat Tabel User sebagai Login

PRIMARY KEY CREATE TABLE user (
-> username VARCHAR(15) NOT NULL,
-> password VARCHAR(10) NOT NULL,
-> PRIMARY KEY(username), UNIQUE(username));
Query OK, 0 rows affected (0.14 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| jmb |
| mysql |
| test |
+--------------------+
4 rows in set (0.03 sec)

mysql> describe user;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(15) | NO | PRI | NULL | |
| password | varchar(10) | NO | | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.03 sec)


//Tabel tbBuku


mysql> CREATE TABLE tbBuku (
-> B_ISBN VARCHAR(15),
-> B_Title VARCHAR(50),
-> B_Authors VARCHAR(50),
-> B_Publisher VARCHAR(50),
-> B_Price Float(50),
-> PRIMARY KEY(B_ISBN), UNIQUE(B_ISBN));
Query OK, 0 rows affected (0.09 sec)


mysql> describe tbBuku;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| B_ISBN | varchar(15) | NO | PRI | | |
| B_Title | varchar(50) | YES | | NULL | |
| B_Authors | varchar(50) | YES | | NULL | |
| B_Publisher | varchar(50) | YES | | NULL | |
| B_Price | double | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)


//Describe tabel and Insert Table

mysql> use jmb;
Database changed
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| jmb |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)

mysql> select * from user;
+------------+----------+
| username | password |
+------------+----------+
| Ninku Reka | Namco |
+------------+----------+
1 row in set (0.00 sec)

mysql> insert into user(username, password) values ('Mbah Kaum', 'iramaya');
Query OK, 1 row affected (0.03 sec)

mysql> select * from user;
+------------+----------+
| username | password |
+------------+----------+
| Mbah Kaum | iramaya |
| Ninku Reka | Namco |
+------------+----------+
2 rows in set (0.00 sec)

mysql> DELETE FROM tbBiodata WHERE id = 10

Query OK, 1 row affected (0.08 sec)

Tidak ada komentar:

Poskan Komentar