Beruflich Dokumente
Kultur Dokumente
Database?
Relational database?
A relational database matches data by using common characteristics found within the data set. The
resulting groups of data are organized and are much easier for people to understand.
A relational database management system (RDBMS) is a database management system (DBMS) that
is based on the relational model as introduced by E. F. Codd. Most popular commercial and open
source databases currently in use are based on the relational model.
Database server
A database server is not a computer program which provides database services to other computer
programs or computers. it is a server that is accessed either through a "back end" running on the user’s
computer which displays requested data which runs on the server and does not responsible for tasks such
as data analysis and storage.
In a master-slave model, database master servers are central and primary locations of data while
database slave servers are synchronized backups of the master acting as proxies.
1
Hal yang diperhatikan
- Performance
- Scurity
- Integrity
- Access
- Data
- Capabilities
- Performance
- Accesbility
- Cost
- Primery Keys
In relational database design, a unique key or primary key is a candidate key to uniquely
identify each row in a table. A unique key or primary key comprises a single column or set of
columns. No two distinct rows in a table can have the same value (or combination of values) in
those columns. Depending on its design, a table may have arbitrarily many unique keys but at
most one primary key.
2
A unique key must uniquely identify all possible rows that exist in a table and not only the
currently existing rows. Examples of unique keys are Social Security numbers (associated with a
specific person[1][2]) or ISBNs (associated with a specific book). Telephone books and dictionaries
cannot use names, words, or Dewey Decimal system numbers as candidate keys
because they do not uniquely identify telephone numbers or words.
- Numeric Data
- Dates and times
- Character
- Binary
MySQL Datatypes
Ty p e Size Description
CHAR[Length] Length bytes A fixed-length field from 0 to 255 characters
long.
VARCHAR(Length) String length + A fixed-length field from 0 to 255 characters
1 bytes long.
TINYTEXT String length + A string with a maximum length of 255
1 bytes characters.
TEXT String length + A string with a maximum length of 65,535
2 bytes characters.
MEDIUMTEXT String length + A string with a maximum length of
3 bytes 16,777,215 characters.
LONGTEXT String length + A string with a maximum length of
4 bytes 4,294,967,295 characters.
TINYINT[Length] 1 byte Range of -128 to 127 or 0 to 255 unsigned.
SMALLINT[Length] 2 bytes Range of -32,768 to 32,767 or 0 to 65535
unsigned.
3
MEDIUMINT[Length] 3 bytes Range of -8,388,608 to 8,388,607 or 0 to
16,777,215 unsigned.
INT[Length] 4 bytes Range of -2,147,483,648 to 2,147,483,647
or 0 to 4,294,967,295 unsigned.
BIGINT[Length] 8 bytes Range of -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807 or 0 to
18,446,744,073,709,551,615 unsigned.
FLOAT 4 bytes A small number with a floating decimal
point.
DOUBLE[Length, 8 bytes A large number with a floating decimal
Decimals] point.
DECIMAL[Length, Length + 1 or A DOUBLE stored as a string, allowing for a
Decimals] Length + 2 fixed decimal point.
bytes
DATE 3 bytes In the format of YYYY-MM-DD.
DATETIME 8 bytes In the format of YYYY-MM-DD HH:MM:SS.
TIMESTAMP 4 bytes In the format of YYYYMMDDHHMMSS;
acceptable range ends inthe year 2037.
TIME 3 bytes In the format of HH:MM:SS
ENUM 1 or 2 bytes Short for enumeration, which means that
each column can haveone of several
possible values.
SET 1, 2, 3, 4, or 8 Like ENUM except that each column can
bytes have more than one ofseveral possible
values.
4
Cara Cepat Membuat Database dan Tabel [PHPMyAdmin]
1. Buka browser Anda
2. lalu ketikkan pada bagian Address: http://localhost/phpmyadmin/, lalu tekan tombol Enter,
3. Untuk membuat database, isikan nama database yang akan dibuat pada bagian Create new database,
misalnya: bukutamu (tidak boleh ada spasi), lalu klik tombol Create. Lihat lagi gambar 1.
4. Maka akan terbentuk sebuah database dengan nama: bukutamu, Anda bisa melihatnya pada bagian
jendela kiri di bawah teks Home. Setelah membuat database, maka langkah selanjutnya adalah
membuat tabel di dalam database tersebut dengan cara mengisikan nama tabel dan jumlah field di
bagian Create new table on database bukutamu, misalnya Name: tamu dan Fields: 4, lalu klik tombol
Go. Lihat gambar 2.
5
6
Gambar 2. Membuat tabel
5. Setelah selesai, klik tombol Save, maka akan terbentuk sebuah tabel dengan nama: tamu beserta field-
field didalamnya. Hasilnya dapat dilihat pada gambar 4.
7
Membuat Database dengan Comand Prompt
1. PENDAHULUAN
Untuk dapat mengakses database, maka seorang user harus login terlebih dahulu
# mysql –u nama_user –p
password : **********
Type 'help;' or '\h' for help. Type '\c' to clear the buffer
NB : Setiap query diakhiri dengan tanda (;). Jika tanda ( ; ) tidak diberikan, maka MySQL
Akan menganggap bahwa query anda belum selesai.
,
mysql> create database amikom;
Untuk melihat apakah database saya sudah ada, gunbakan kembali query show databases;
3. MEMBUAT TABLE
8
2 rows in set (0.00 sec)
LAMPIRAN
# mysql –version
4. Masuk ke MySQL
Ketikkan mysql pada sistem agar kita bisa masuk ke dalam database MySQL.
4. Melihat Database
Ingat:
nama_database dirubah menjadi nama database sesuai dengan anda. Dalam
tutorial ini kita akan membuat database latihan, sehingga perintahnya
menjadi:
6. Menggunakan Database;
9
Untuk menggunakan database yang ada di MySQL, ketikkan perintah:
Karena kita telah membuat database latihan, maka kita akan menggunakan database ini, sehingga
perintah tersebut menjadi:
7. Membuat Table
Tipe-tipe
data pada MySQL bermacam-macam dan dapat dilihat lengkap di sini.
panjang_karakter merupakan jumlah karakter maksimum yang ditampung di
dalam sebuah field. Kali ini, kita akan membuat tabel alamat yang
berisi field no, nama, alamat, kota, telepon.
8. Melihat Table
Namun, untuk melihat sebuah table yang lebih lengkap beserta tipe-tipe datanya, ikuti format berikut:
Apabila kita ingin merubah nama field pada tabel yang sudah jadi, maka harus mengikuti format:
Pada perintah ini, tipe_data dan panjang_karakter dapat dirubah. Dalam kasus kita:
10
10. Merubah Tipe Data
Jika kita ingin merubah tipe data sebuah field, maka harus mengikuti format:
11
14. Mengubah Data-Data
Contoh:
maka nama seseorang yang berada di nomor 2 akan berubah menjadi hari irah.
Agar
bisa lebih mengerti dengan pembahasan ini, cobalah tambah beberapa data
seperti pada poin 13 dengan beberapa field memiliki nilai yang sama.
Karena untuk melihat table memiliki banyak format, maka kita bisa
melihat sebuah tabel dengan berbagai macam cara, seperti:
Format:
Contoh:
Format:
Contoh:
Format:
12
Contoh:
Format:
Contoh:
Format:
Contoh kita akan menampilkan data yang dimulai dari baris kedua sampai keenam, maka perintahnya
adalah:
f. Mengurutkan data
Format:
Klausa format ini ada 2 yaitu asc yaitu akan mengurutkan data naik dari yang terkecil dan desc yaitu
kebalikannya.
Format:
Opearator_logika disini ada 2 yaitu and dan or. Untuk melihat perbedaan diantara keduanya, perhatikan
gambar dibawah ini:
Format:
13
> select nama_field_yang_mau_ditampilkan from nama_table where nama_field between isi_field and
isi_field;
Format:
Nama Fungsi
Deskripsi
SUM()
AVG()
MAX()
MIN()
COUNT()
14
Format:
Format:
Format:
> quit;
atau
> exit;
15