Senin, 22 Oktober 2012

Relational - Database

Diposting oleh Kuliner Malang di 05.31
Halo , kita ketemu lagi?Aku abis dapet tugas nih,pelajaran Basis Data atau Data Base.Pelajarin yuk ?

1.Pertama,kalian tulis dulu di notepad
CREATE TABLE siswa(
NIS varchar(10) PRIMARY KEY,
Nama Varchar (30),
Kelas varchar (20),
No_Telp varchar (30)
)engine = InnodB;
CREATE TABLE ekskul(
Id_ekskul varchar(10) PRIMARY KEY,
Nama varchar(30),
Tempat varchar(30),
Hari varchar (20),
Jam varchar (20)
)engine = Innodb;
CREATE TABLE pelatih(
ID_pelatih varchar(10) PRIMARY KEY,
No_kurikuler varchar(10),
Tanggal varchar(10)
)engine = InnodB;

2.Simpan dan masukkan ke folder bernama Latihan , beri nama latihan.sql
3.Buka cmd cari di All Programs padaWindows

4.Masukkan Syntaq :
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Desy>C: //nama datamu di Computer

C:\Users\Desy>cd..

C:\Users>cd..

C:\>cd _PHP //nama file 1

C:\_PHP>cd xampp //nama file 2

C:\_PHP\xampp>cd mysql //nama fie 3

C:\_PHP\xampp\mysql>cd bin //nama file 4

C:\_PHP\xampp\mysql\bin>mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.5.16 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cdcol              |
| dbekskul           |
| dbpegawai          |
| dbpegawai2         |
| dbperusahaan       |
| ekstrakurikuler    |
| mysql              |
| performance_schema |
| phpmyadmin         |
| test               |
| webauth            |
+--------------------+
12 rows in set (0.00 sec)

mysql> use Ekstrakurikuler;
Database changed

mysql> desc siswa
    -> ;
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| NIS     | varchar(10) | NO   | PRI | NULL    |       |
| Nama    | varchar(30) | YES  |     | NULL    |       |
| Kelas   | varchar(20) | YES  |     | NULL    |       |
| No_Telp | varchar(30) | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> desc pelatih;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| ID_pelatih   | varchar(10) | NO   | PRI | NULL    |       |
| No_kurikuler | varchar(10) | YES  |     | NULL    |       |
| Tanggal      | varchar(10) | YES  |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+
3 rows in set (0.02 sec)

mysql> desc ekskul;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Id_ekskul | varchar(10) | NO   | PRI | NULL    |       |
| Nama      | varchar(30) | YES  |     | NULL    |       |
| Tempat    | varchar(30) | YES  |     | NULL    |       |
| Hari      | varchar(20) | YES  |     | NULL    |       |
| Jam       | varchar(20) | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.02 sec)

Ini adalah syntaq untu menambahkan 1 field dalam 1 folder :
mysql>
mysql> ALTER TABLE siswa ADD Nilai INT;
Query OK, 0 rows affected (0.10 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc siswa;
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| NIS     | varchar(10) | NO   | PRI | NULL    |       |
| Nama    | varchar(30) | YES  |     | NULL    |       |
| Kelas   | varchar(20) | YES  |     | NULL    |       |
| No_Telp | varchar(30) | YES  |     | NULL    |       |
| Nilai   | int(11)     | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.07 sec)

Ini adalah cara untuk mengganti nama 1 field dalam 1 folder:
mysql> ALTER TABLE ekskul
    -> CHANGE Hari Tanggal VARCHAR(10);
Query OK, 0 rows affected (0.06 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc ekskul;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Id_ekskul | varchar(10) | NO   | PRI | NULL    |       |
| Nama      | varchar(30) | YES  |     | NULL    |       |
| Tempat    | varchar(30) | YES  |     | NULL    |       |
| Tanggal   | varchar(10) | YES  |     | NULL    |       |
| Jam       | varchar(20) | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.02 sec)

Dan ini adalah syntaq untuk menghapus 1 field dalam 1 folder :
mysql> ALTER TABLE pelatih DROP Tanggal;
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc pelatih;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| ID_pelatih   | varchar(10) | NO   | PRI | NULL    |       |
| No_kurikuler | varchar(10) | YES  |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)

mysql>

0 komentar:

Posting Komentar

 

Desi Template by Ipietoon Blogger Template | Gadget Review