Saya mau berbagi lagi nih,barusan saya dapet tugas disuruh membuat tabel foreign key pada cmd (CommandPrompt).
1.Buka cmd
2.Masukkan syntaqnya :
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Desy>C:
C:\Users\Desy>cd..
C:\Users>cd..
C:\>cd _PHP
C:\_PHP>cd mysql
The system cannot find the path specified.
C:\_PHP>cd xampp
C:\_PHP\xampp>cd mysql
C:\_PHP\xampp\mysql>cd bin
C:\_PHP\xampp\mysql\bin>mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
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> show tables;
+---------------------------+
| Tables_in_ekstrakurikuler |
+---------------------------+
| ekskul |
| pelatih |
| siswa |
+---------------------------+
3 rows in set (0.00 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 | |
| Tanggal | varchar(10) | YES | | NULL | |
| Jam | varchar(20) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.14 sec)
mysql> create table nilai (
-> NIS varchar(10) , ID_ekskul varchar(10) , nilai varchar(10),
-> FOREIGN KEY (NIS) REFERENCES siswa(NIS) ON DELETE CASCADE ON UPDATE CASCADE,
-> FOREIGN KEY (ID_ekskul) REFERENCES ekskul (Id_ekskul) ON DELETE CASCADE engine = InnodB;
Query OK, 0 rows affected (0.15 sec)
mysql> desc nilai;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| NIS | varchar(10) | YES | MUL | NULL | |
| ID_ekskul | varchar(10) | YES | MUL | NULL | |
| nilai | varchar(10) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.02 sec)
mysql> create table Absensi (
-> NIS varchar(10) , ID_ekskul varchar(10) , ket varchar(30),
-> FOREIGN KEY (NIS) REFERENCES siswa(NIS) ON DELETE CASCADE ON UPDATE CASCADE,
-> FOREIGN KEY (ID_ekskul) REFERENCES ekskul (Id_ekskul) ON DELETE CASCADE ) engine = InnodB;
Query OK, 0 rows affected (0.09 sec)
mysql> desc Absensi;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| NIS | varchar(10) | YES | MUL | NULL | |
| ID_ekskul | varchar(10) | YES | MUL | NULL | |
| ket | varchar(30) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.03 sec)
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.05 sec)
mysql> create table Jadwal (
-> ID_pelatih varchar(10) , ID_ekskul varchar(10) , Tanggal varchar(10),
-> FOREIGN KEY (ID_pelatih) REFERENCES pelatih(ID_pelatih) ON DELETE CASCADE ON UPDATE CASCADE,
-> FOREIGN KEY (ID_ekskul) REFERENCES ekskul (Id_ekskul) ON DELETE CASCADE ) engine = InnodB;
Query OK, 0 rows affected (0.10 sec)
mysql> desc Jadwal;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| ID_pelatih | varchar(10) | YES | MUL | NULL | |
| ID_ekskul | varchar(10) | YES | MUL | NULL | |
| Tanggal | varchar(10) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
3 rows in set (0.02 sec)
mysql> Bye
Ctrl-C -- exit!
C:\_PHP\xampp\mysql\bin>
Blogroll
Labels
- Agama (1)
- ATTITUDE (2)
- Basis Data (4)
- cerita (4)
- cerpen (9)
- Hijrah (2)
- IPS (1)
- Java (5)
- Kewirausahaan (1)
- Mini Novel (1)
- PHP (7)
- PKN (1)
- Puisi (1)
- Sekilas Cerita (1)
- Sekilas Cerita :D (8)
About
Senin, 22 Oktober 2012
Langganan:
Posting Komentar (Atom)
2 komentar:
lu yang buat sendiri ini desain interface nya?? keren kaka ^ ^
makasih buat artikel nya,kalau mau lebih basus di kasih cara buat mengabungkan 3 dalam 1 :)
Posting Komentar