Minggu, 26 Desember 2010

View MySQL

View bisa dikatakan summary dari tabel atau beberapa tabel, dengan view, kita bisa gabungkan beberapa tabel sekaligus dan view ini tersimpan di sisi server, sehingga nanti penggunaannya tinggal panggil saja, berikut contohnya, :D:\its me\xampp\mysql\bin>mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.41-community-nt MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> create database forum;
Query OK, 1 row affected (0.00 sec)

mysql> use forum;
Database changed
mysql> create table barang(kode_barang char(3) not null primary key default’0′,n
ama_barang char(30),harga_barang int);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into barang values(’001′,’mobil’,50000000);
Query OK, 1 row affected (0.05 sec)

mysql> create table jual(tgl date,kode char(3),jml_jual int);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into jual values(’2007-01-01′,’001′,3);
Query OK, 1 row affected (0.00 sec)

mysql> create view jualan_view as select DATE_FORMAT(b.tgl,’%d %M %Y’) as tgl,b.kode,a.nama_barang, a.harga_barang,b.jml_jual,(a.harga_barang*b.jml_jual) as total from jual b, barang a where
b.kode=a.kode_barang;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from jualan_view;
==========================================
| tgl | kode | nama_barang | harga_barang | jml_jual | total |
===========================================
| 01 January 2007 | 001 | mobil | 50000000 | 3 | 150000000 |
+———————–+——+————-+————–+———-+
1 row in set (0.00 sec)

Sumber :

Tidak ada komentar:

Poskan Komentar