Tabel merupakan alat bantu visual, di samping grafik dan peta. Sedangkan fungsinya adalah menjelaskan suatu fakta atau informasi secara singkat dan lebih menarik daripada dengan kata-kata. Selain itu tabel juga berfungsi untuk mendukung penulis menyampaikan ide atau gagasan sehingga dapat memengaruhi dan meyakinkan pembaca.
Mengenai table management dapat kita golongkan menjadi dua yaitu :
- DDL - Data Definition Language adalah sekumpulan perintah SQL yang biasa digunakan untuk membuat (create), mengubah (alter) dan menghapus (drop) struktur dan definisi metadata dari objek-objek database.
- DML - Data Manipulation Language merupakan kumpulan perintah SQL yang dipakai dalam proses pengolahan isi data dalam table seperti memasukkan, merubah dan menghapus isi data. Tetapi, tidak terkait dengan perubahan struktur dan definisi tipe data dari objek database.
Objek-objek database pada yang dimaksud dalam MySQ diantaranya adalah : Database, TableView, Index, Procedure, (Stored Procedure), Function, Trigger
2. Tugas Praktikum
Postgre SQL
Table "public.identitasnim"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahiridn | date |
status_idn | boolean |
alamat_idn | text |
db_muzakki13650026=# create table pegawai (Id_idn Integer Not Null, namaDepan_id
n Varchar(10), namaBelakang_idn Varchar(10), tgl_lahir_idn Date, status_idn Bool
ean, Alamat_idn Text);
CREATE TABLE
db_muzakki13650026=# \d pegawai
Table "public.pegawai"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
alamat_idn | text |
db_muzakki13650026=# alter table pegawai drop column "alamat_idn";
ALTER TABLE
db_muzakki13650026=# \d pegawai
Table "public.pegawai"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
db_muzakki13650026=# alter table pegawai add column "pekerjaan" varchar;
ALTER TABLE
db_muzakki13650026=# \d pegawai
Table "public.pegawai"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
pekerjaan | character varying |
db_muzakki13650026=# alter table pegawai drop column "pekerjaan";
ALTER TABLE
db_muzakki13650026=# alter table pegawai add column "pekerjaan" Varchar;
ALTER TABLE
db_muzakki13650026=# \d pegawai
Table "public.pegawai"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
pekerjaan | character varying |
db_muzakki13650026=# alter table pegawai rename to pekerjaNIM;
ALTER TABLE
db_muzakki13650026=# \d pekerjaNIM
Table "public.pekerjanim"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
pekerjaan | character varying |
db_muzakki13650026=# alter table pekerjaNIM rename column "pekerjaan" to alamat_
idn;
ALTER TABLE
db_muzakki13650026=# \d pegawai
Did not find any relation named "pegawai".
db_muzakki13650026=# \dpekerjaNIM
Access privileges
Schema | Name | Type | Access privileges | Column access privileges
--------+--------------+-------+-------------------+--------------------------
public | identitasnim | table | |
public | pekerjanim | table | |
(2 rows)
db_muzakki13650026=# \d pekerjaNIM
Table "public.pekerjanim"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
alamat_idn | character varying |
db_muzakki13650026=# alter table pekerjaNIM alter column alamat_idn varchar text
;
ERROR: syntax error at or near "varchar"
LINE 1: alter table pekerjaNIM alter column alamat_idn varchar text;
^
db_muzakki13650026=# alter table pekerjaNIM alter column alamat_idn Varchar text
;
ERROR: syntax error at or near "Varchar"
LINE 1: alter table pekerjaNIM alter column alamat_idn Varchar text;
^
db_muzakki13650026=# alter table pekerjaNIM alter column alamat_idn type text;
ALTER TABLE
db_muzakki13650026=# \d pekerjaNIM
Table "public.pekerjanim"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
alamat_idn | text |
db_muzakki13650026=# drop table pekerjaNIM
db_muzakki13650026-# \d
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+----------
public | identitasnim | table | postgres
public | pekerjanim | table | postgres
(2 rows)
db_muzakki13650026-# drop table pekerjanim
db_muzakki13650026-# \d
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+----------
public | identitasnim | table | postgres
public | pekerjanim | table | postgres
(2 rows)
db_muzakki13650026-# \d pekerjanim
Table "public.pekerjanim"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
alamat_idn | text |
db_muzakki13650026-# drop table pekerjanim
db_muzakki13650026-# \l
List of databases
Name | Owner | Encoding | Collate |
Ctype | Access privileges
--------------------+----------+----------+----------------------------+--------
--------------------+-----------------------
dahlan13650121 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
db_muzakki13650026 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
fikri13650031 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
hikam10650034 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
postgres | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
rahmat13650112 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
retno_13650087 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
template0 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 | =c/postgres +
| | | |
| postgres=CTc/postgres
template1 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 | =c/postgres +
| | | |
| postgres=CTc/postgres
wachit13650053 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
(10 rows)
db_muzakki13650026-# drop table pekerjanim
db_muzakki13650026-# create temporary table mahasiswa_sementara (id, nama, tangg
al lahir);
ERROR: syntax error at or near "drop"
LINE 2: drop table pekerjanim
^
db_muzakki13650026=# \d mahasiswa_sementara
Did not find any relation named "mahasiswa_sementara".
db_muzakki13650026=# create temporary table mahasiswa_sementara (id varchar not
null, nama varchar, tanggal lahir varchar);
ERROR: syntax error at or near "varchar"
LINE 1: ... (id varchar not null, nama varchar, tanggal lahir varchar);
^
db_muzakki13650026=# drop table pekerjanim;
DROP TABLE
db_muzakki13650026=# \d
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+----------
public | identitasnim | table | postgres
(1 row)
db_muzakki13650026=# create temporary table mahasiswa_sementara (id, nama, tangg
al_lahir);
ERROR: syntax error at or near ";"
LINE 1: ...mporary table mahasiswa_sementara (id, nama, tanggal_lahir);
^
db_muzakki13650026=# create temporary table mahasiswa_sementara (id integer not
null, nama varchar not null, tanggal lahir varchar not null);
ERROR: syntax error at or near "varchar"
LINE 1: ...er not null, nama varchar not null, tanggal lahir varchar no...
^
db_muzakki13650026=# create temporary table mahasiswa_sementara (id integer not
null, nama varchar(15), tanggal_lahir date );
CREATE TABLE
db_muzakki13650026=# \d mahasiswa_sementara
Table "pg_temp_3.mahasiswa_sementara"
Column | Type | Modifiers
---------------+-----------------------+-----------
id | integer | not null
nama | character varying(15) |
tanggal_lahir | date |
db_muzakki13650026=# grant all on table pekerjanim;
ERROR: syntax error at or near ";"
LINE 1: grant all on table pekerjanim;
^
db_muzakki13650026=# \d
List of relations
Schema | Name | Type | Owner
-----------+---------------------+-------+----------
pg_temp_3 | mahasiswa_sementara | table | postgres
public | identitasnim | table | postgres
(2 rows)
db_muzakki13650026=# grant all on table identitasnim;
ERROR: syntax error at or near ";"
LINE 1: grant all on table identitasnim;
^
db_muzakki13650026=# revoke all on table identitasnim from muzakki;
REVOKE
db_muzakki13650026=# grant all on table identitasnim to muzakki;
GRANT
db_muzakki13650026=# create temporary table Gaji (gaji_kotor integer, pajak inte
ger, gaji_bersih integer) inherits (identitasnim);
CREATE TABLE
db_muzakki13650026=# \d
List of relations
Schema | Name | Type | Owner
-----------+---------------------+-------+----------
pg_temp_3 | gaji | table | postgres
pg_temp_3 | mahasiswa_sementara | table | postgres
public | identitasnim | table | postgres
(3 rows)
db_muzakki13650026=# \d gaji
Table "pg_temp_3.gaji"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahiridn | date |
status_idn | boolean |
alamat_idn | text |
gaji_kotor | integer |
pajak | integer |
gaji_bersih | integer |
Inherits: identitasnim
db_muzakki13650026=# anda gokill!;
ERROR: syntax error at or near "anda"
LINE 1: anda gokill!;
^
db_muzakki13650026=#
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahiridn | date |
status_idn | boolean |
alamat_idn | text |
db_muzakki13650026=# create table pegawai (Id_idn Integer Not Null, namaDepan_id
n Varchar(10), namaBelakang_idn Varchar(10), tgl_lahir_idn Date, status_idn Bool
ean, Alamat_idn Text);
CREATE TABLE
db_muzakki13650026=# \d pegawai
Table "public.pegawai"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
alamat_idn | text |
db_muzakki13650026=# alter table pegawai drop column "alamat_idn";
ALTER TABLE
db_muzakki13650026=# \d pegawai
Table "public.pegawai"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
db_muzakki13650026=# alter table pegawai add column "pekerjaan" varchar;
ALTER TABLE
db_muzakki13650026=# \d pegawai
Table "public.pegawai"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
pekerjaan | character varying |
db_muzakki13650026=# alter table pegawai drop column "pekerjaan";
ALTER TABLE
db_muzakki13650026=# alter table pegawai add column "pekerjaan" Varchar;
ALTER TABLE
db_muzakki13650026=# \d pegawai
Table "public.pegawai"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
pekerjaan | character varying |
db_muzakki13650026=# alter table pegawai rename to pekerjaNIM;
ALTER TABLE
db_muzakki13650026=# \d pekerjaNIM
Table "public.pekerjanim"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
pekerjaan | character varying |
db_muzakki13650026=# alter table pekerjaNIM rename column "pekerjaan" to alamat_
idn;
ALTER TABLE
db_muzakki13650026=# \d pegawai
Did not find any relation named "pegawai".
db_muzakki13650026=# \dpekerjaNIM
Access privileges
Schema | Name | Type | Access privileges | Column access privileges
--------+--------------+-------+-------------------+--------------------------
public | identitasnim | table | |
public | pekerjanim | table | |
(2 rows)
db_muzakki13650026=# \d pekerjaNIM
Table "public.pekerjanim"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
alamat_idn | character varying |
db_muzakki13650026=# alter table pekerjaNIM alter column alamat_idn varchar text
;
ERROR: syntax error at or near "varchar"
LINE 1: alter table pekerjaNIM alter column alamat_idn varchar text;
^
db_muzakki13650026=# alter table pekerjaNIM alter column alamat_idn Varchar text
;
ERROR: syntax error at or near "Varchar"
LINE 1: alter table pekerjaNIM alter column alamat_idn Varchar text;
^
db_muzakki13650026=# alter table pekerjaNIM alter column alamat_idn type text;
ALTER TABLE
db_muzakki13650026=# \d pekerjaNIM
Table "public.pekerjanim"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
alamat_idn | text |
db_muzakki13650026=# drop table pekerjaNIM
db_muzakki13650026-# \d
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+----------
public | identitasnim | table | postgres
public | pekerjanim | table | postgres
(2 rows)
db_muzakki13650026-# drop table pekerjanim
db_muzakki13650026-# \d
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+----------
public | identitasnim | table | postgres
public | pekerjanim | table | postgres
(2 rows)
db_muzakki13650026-# \d pekerjanim
Table "public.pekerjanim"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahir_idn | date |
status_idn | boolean |
alamat_idn | text |
db_muzakki13650026-# drop table pekerjanim
db_muzakki13650026-# \l
List of databases
Name | Owner | Encoding | Collate |
Ctype | Access privileges
--------------------+----------+----------+----------------------------+--------
--------------------+-----------------------
dahlan13650121 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
db_muzakki13650026 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
fikri13650031 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
hikam10650034 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
postgres | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
rahmat13650112 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
retno_13650087 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
template0 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 | =c/postgres +
| | | |
| postgres=CTc/postgres
template1 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 | =c/postgres +
| | | |
| postgres=CTc/postgres
wachit13650053 | postgres | UTF8 | English_United States.1252 | English
_United States.1252 |
(10 rows)
db_muzakki13650026-# drop table pekerjanim
db_muzakki13650026-# create temporary table mahasiswa_sementara (id, nama, tangg
al lahir);
ERROR: syntax error at or near "drop"
LINE 2: drop table pekerjanim
^
db_muzakki13650026=# \d mahasiswa_sementara
Did not find any relation named "mahasiswa_sementara".
db_muzakki13650026=# create temporary table mahasiswa_sementara (id varchar not
null, nama varchar, tanggal lahir varchar);
ERROR: syntax error at or near "varchar"
LINE 1: ... (id varchar not null, nama varchar, tanggal lahir varchar);
^
db_muzakki13650026=# drop table pekerjanim;
DROP TABLE
db_muzakki13650026=# \d
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+----------
public | identitasnim | table | postgres
(1 row)
db_muzakki13650026=# create temporary table mahasiswa_sementara (id, nama, tangg
al_lahir);
ERROR: syntax error at or near ";"
LINE 1: ...mporary table mahasiswa_sementara (id, nama, tanggal_lahir);
^
db_muzakki13650026=# create temporary table mahasiswa_sementara (id integer not
null, nama varchar not null, tanggal lahir varchar not null);
ERROR: syntax error at or near "varchar"
LINE 1: ...er not null, nama varchar not null, tanggal lahir varchar no...
^
db_muzakki13650026=# create temporary table mahasiswa_sementara (id integer not
null, nama varchar(15), tanggal_lahir date );
CREATE TABLE
db_muzakki13650026=# \d mahasiswa_sementara
Table "pg_temp_3.mahasiswa_sementara"
Column | Type | Modifiers
---------------+-----------------------+-----------
id | integer | not null
nama | character varying(15) |
tanggal_lahir | date |
db_muzakki13650026=# grant all on table pekerjanim;
ERROR: syntax error at or near ";"
LINE 1: grant all on table pekerjanim;
^
db_muzakki13650026=# \d
List of relations
Schema | Name | Type | Owner
-----------+---------------------+-------+----------
pg_temp_3 | mahasiswa_sementara | table | postgres
public | identitasnim | table | postgres
(2 rows)
db_muzakki13650026=# grant all on table identitasnim;
ERROR: syntax error at or near ";"
LINE 1: grant all on table identitasnim;
^
db_muzakki13650026=# revoke all on table identitasnim from muzakki;
REVOKE
db_muzakki13650026=# grant all on table identitasnim to muzakki;
GRANT
db_muzakki13650026=# create temporary table Gaji (gaji_kotor integer, pajak inte
ger, gaji_bersih integer) inherits (identitasnim);
CREATE TABLE
db_muzakki13650026=# \d
List of relations
Schema | Name | Type | Owner
-----------+---------------------+-------+----------
pg_temp_3 | gaji | table | postgres
pg_temp_3 | mahasiswa_sementara | table | postgres
public | identitasnim | table | postgres
(3 rows)
db_muzakki13650026=# \d gaji
Table "pg_temp_3.gaji"
Column | Type | Modifiers
------------------+-----------------------+-----------
id_idn | integer | not null
namadepan_idn | character varying(10) |
namabelakang_idn | character varying(10) |
tgl_lahiridn | date |
status_idn | boolean |
alamat_idn | text |
gaji_kotor | integer |
pajak | integer |
gaji_bersih | integer |
Inherits: identitasnim
db_muzakki13650026=# anda gokill!;
ERROR: syntax error at or near "anda"
LINE 1: anda gokill!;
^
db_muzakki13650026=#
MySQL - SQLyog
3. Postgre vs MySQL (SQLyog)
Berikut adalah perbandingan antara Postgre dengan MySQL (menggunakan SQLyog) dalam hal menuliskan querry atau perintah - perintahnya.
Querry
|
PosgreSQL
|
MySQL (SQLyog)
|
Merubah Nama Kolom
|
alter table namatablerename
column “namakolom asal” to namakolombaru;
|
ALTER TABLE NAMATABLE CHANGE NAMAKOLOMASAL
NAMAKOLOMBARU TIPEDATA;
|
Struktur tabel
|
\d namatabel;
|
DESC NAMATABLE;
|
Revoke
|
revoke all on table namatabel
from namauser;
|
REVOKE ALL ON TABLE NAMATABEL
FROM ‘NAMAUSER’@’HOST’;
|
Grant
|
grant all on table namatabel
to namauser;
|
GRANT ALL ON TABLE NAMATABEL
TO ‘NAMAUSER’@’HOST’;
|
Revoke Select
|
revoke select on tabel
namatabel from namauser;
|
REVOKE SELECT ON TABEL
NAMATABEL FROM ‘NAMAUSER’@’HOST’;
|
Mengecek Hak Akses User Lain
|
buka window baru (SQL shell) kemudian login dengan
user lain yang telah direvoke
|
SHOW GRANTS FOR ‘NAMAUSER’@’HOST’
|
4. Kesimpulan
5. Tugas ERD
Pada postingan yang lalu, seingat saya, kemarin saya telah membuat ERD "mahasiswa yang tinggal di ma'had" . Berkenaan dengan hal tersebut, saya akan membuat dtabasenya dengan menggubnakan SQLyog.6. Daftar Contekan
- http://catatan-kuliah-teknik-informatika.blogspot.com/search/label/Praktikum%20Desain%20Basis%20Data
- http://azilmoza.blogspot.com/2012/10/pembuatan-dan-manajemen-tabel-sebuah.html?showComment=1412008032304#c6936165204066991586
- http://mysql.phi-integration.com/sql/apa-itu-dml-ddl
Untuk laporan minggu depan, hasil praktikum PosgreSQL dan mySQL di print Screen aja, jangan langsung di copas kayak gitu.....
BalasHapus