Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

Struktur Data PostreSQL 9.2. Pengenalan PostgreSQL.

Presentasi serupa

Presentasi berjudul: "Struktur Data PostreSQL 9.2. Pengenalan PostgreSQL."— Transcript presentasi:

1 Struktur Data PostreSQL 9.2

2 Pengenalan PostgreSQL

3 PostgreSQL PostgreSQL is a powerful, open source object-relational database system. More than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness. Based on POSTGRES, Version 4.2, developed at the University of California at Berkeley Computer Science Department.

4 Feature complex queries foreign keys triggers views transactional integrity Multi-version concurrency control point in time recovery tablespaces asynchronous replication nested transactions (savepoints) online/hot backups a sophisticated query planner/optimizer write ahead logging for fault tolerance PostGIS

5 Limitation LimitValue Maximum Database SizeUnlimited Maximum Table Size32 TB Maximum Row Size1.6 TB Maximum Field Size1 GB Maximum Rows per TableUnlimited Maximum Columns per Table depending on column types Maximum Indexes per TableUnlimited

6 Advantages Extensible data types functions operators aggregate functions index methods procedural languages Cross Platform Designed for high volume environments GUI database design and administration tools Free..!

7 Cross Platform Distribution BSD FreeBSD OpenBSD Linux RedHat/CentOS/Fedora/Scientific families Linux Debian GNU/Linux Ubuntu Linux SuSE and OpenSuSE Other Linux Mac OS X Solaris Windows Source Code

8 GiST GiST (Generalized Search Tree) indexing advanced system which brings together a wide array of different sorting and searching algorithms B-tree, B+-tree, R-tree, partial sum trees, ranked B+-trees and many others. provides an interface which allows both the creation of custom data types as well as extensible query methods with which to search them. flexibility to specify what you store, how you store it, and the ability to define new ways to search through Foundation for many public projects that use PostgreSQL OpenFTS PostGIS

9 OpenFTS OpenFTS (Open Source Full Text Search engine) is an advanced PostgreSQL-based search engine that provides online indexing of data and relevance ranking for database searching. Close integration with database allows use of metadata to restrict search results.

10 PostGIS PostGIS adds support for geographic objects to the PostgreSQL object-relational database. PostgreSQL used as a backend spatial database for geographic information systems (GIS). Like ESRI's SDE or Oracle's Spatial extension. PostGIS follows the OpenGIS "Simple Features Specification for SQL" and has been certified as compliant with the "Types and Functions" profile. PostGIS is open source spatial database technology.

11 Instalasi …..

12 PgAdmin III

13 SQL Shell

14 Referensi SQL tml tml

15 RDBMS 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 Data stored in tables Column  Field Row  Data

16 Normalization Eliminating redundant data, for example, storing the same data in more than one tables. Ensuring data dependencies make sense. Normalization form First Normal Form (1NF) Second Normal Form (2NF) Third Normal Form (3NF)

17 SQL SQL is structured Query Language which is a computer language for storing, manipulating and retrieving data stored in relational database. Standard language for Relation Database System. All relational database management systems uses SQL as standard database language Also they are using different dialects, Such as: MS SQL Server using T-SQL, Oracle using PL/SQL, MS Access version of SQL is called JET SQL (native format )etc

18 Query Process

19 SQL Commands: DDL - Data Definition Language: Statement yang digunakan untuk membangun atau memodifikasi struktur table atau objek lainnya dalam database. DML - Data Manipulation Language: Statement yang digunakan untuk memanipulasi data DCL - Data Control Language: Statement yang digunakan untuk menciptakan roles, permission dan melakukan control akses dalam database DQL - Data Query Language: Statement untuk mengambil data.


21 ROLE User untuk database Administrasi ROLE Menciptakan Menghapus Mengubah

22 Mengelola Role Menciptakan Role CREATE ROLE ; Menghapus Role DROP ROLE ; Melihat Role SELECT rolname FROM pg_roles;



25 Administrasi Database

26 Mengelola Database Menampilkan db SELECT datname FROM pg_database Menciptakan db CREATE DATABASE CREATE DATABASE OWNER ;

27 Mengelola Database Menggunakan db \connect \c Menghapus db DROP DATABASE

28 Manajemen Tabel

29 Menampilkan Menciptakan Menghapus Mengubah Mendeskripsikan

30 Struktur Table Data disimpan dalam table Column  Data Field Row  Data/Fakta Column memiliki data type Data disimpan sesuai data type column tersebut.

31 Data Type Numeric Monetary Character Binary Data Type Date/Time Boolean Enumerated Type Geometric Network Address Type Bit String Text Search Type UUID XML JSON Array Composite Range Type Object Identifier Pseudo Type

32 Numeric Type NameStorage SizeDescriptionRange smallint2 bytessmall-range integer to integer4 bytestypical choice for integer to bigint8 byteslarge-range integer to decimalvariable user-specified precision, exact up to digits before the decimal point; up to digits after the decimal point numericvariable user-specified precision, exact up to digits before the decimal point; up to digits after the decimal point real4 bytesvariable-precision, inexact6 decimal digits precision double precision8 bytesvariable-precision, inexact15 decimal digits precision smallserial2 bytes small autoincrementing integer 1 to serial4 bytesautoincrementing integer1 to bigserial8 bytes large autoincrementing integer 1 to

33 Character Type NameDescription character varying(n), varchar(n)variable-length with limit character(n), char(n)fixed-length, blank padded textvariable unlimited length

34 Date/Time Type NameStorage SizeDescriptionLow ValueHigh ValueResolution timestamp [ (p) ] [ without time zone ] 8 bytes both date and time (no time zone) 4713 BC AD 1 microsecond / 14 digits timestamp [ (p) ] with time zone 8 bytes both date and time, with time zone 4713 BC AD 1 microsecond / 14 digits date4 bytes date (no time of day) 4713 BC AD1 day time [ (p) ] [ without time zone ] 8 bytes time of day (no date) 00:00:0024:00:00 1 microsecond / 14 digits time [ (p) ] with time zone 12 bytes times of day only, with time zone 00:00: :00: microsecond / 14 digits interval [ fields ] [ (p) ] 12 bytestime interval years years 1 microsecond / 14 digits

35 Boolean NameStorage SizeDescription boolean1 bytestate of true or false

36 Enumerated Type CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); CREATE TABLE person ( name text, current_mood mood ); INSERT INTO person VALUES ('Moe', 'happy'); SELECT * FROM person WHERE current_mood = 'happy'; name | current_mood Moe | happy

37 Geometric NameStorage SizeRepresentationDescription point16 bytesPoint on a plane(x,y) line32 bytes Infinite line (not fully implemented) ((x1,y1),(x2,y2)) lseg32 bytesFinite line segment((x1,y1),(x2,y2)) box32 bytesRectangular box((x1,y1),(x2,y2)) path16+16n bytes Closed path (similar to polygon) ((x1,y1),...) path16+16n bytesOpen path[(x1,y1),...] polygon40+16n bytes Polygon (similar to closed path) ((x1,y1),...) circle24 bytesCircle (center point and radius)

38 Administrasi Table Menampilkan Table SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

39 Menciptakan Tabel CREATE TABLE weather ( city varchar(80), temp_lo int, -- low temperature temp_hi int, -- high temperature prcp real, -- precipitation date date );

40 Menghapus Tabel DROP TABLE ;

41 Mengubah Tabel ALTER TABLE RENAME TO ;

42 Mengubah Tabel Add Column ALTER TABLE products ADD COLUMN description text CHECK (description <> ''); Remove Column ALTER TABLE products DROP COLUMN description CASCADE; Rename Column ALTER TABLE products RENAME COLUMN product_no TO product_number; Change Data Type ALTER TABLE products ALTER COLUMN price TYPE numeric(10,2);

43 Tabel mahasiswa UNAND Namavarchar(100) NIMvarchar(10) Fakultasvarchar(32) Jurusanvarchar(32) Jenis KelaminBoolean/varchar(1) Tempat Lahirvarchar(32) Tanggal Lahirdate

44 Constraint & Default Value Default Value ALTER TABLE products ALTER COLUMN price SET DEFAULT 7.77; Adding Constraint ALTER TABLE products ADD CHECK (name <> ''); ALTER TABLE products ADD CONSTRAINT some_name UNIQUE (product_no); ALTER TABLE products ADD FOREIGN KEY (product_group_id) REFERENCES product_groups; Removing Constraint ALTER TABLE products DROP CONSTRAINT some_name;

45 Constraints Check Constraints CHECK( ) Not-Null Constraints NOT NULL Unique Constraints UNIQUE Primary Keys PRIMARY KEY Foreign Keys REFERENCES ( ) Exclusion Constraints EXCLUDE USING gist (c WITH &&)

46 Deskripsi Tabel SELECT column_name FROM information_schema.columns WHERE table_name =‘ ‘;

47 Manipulasi Data

48 Insert Data INSERT INTO VALUES (,,…) INSERT INTO (,, …) VALUES (,, …)

49 Update Data UPDATE SET = WHERE

50 Delete Data DELETE FROM DELETE FROM WHERE condition

51 Query Data SELECT * FROM ; SELECT [ ALL | DISTINCT [ ON ( expression [,...] ) ] ] * | expression [ [ AS ] output_name ] [,...] [ FROM from_item [,...] ] [ WHERE condition ] [ GROUP BY expression [,...] ] [ HAVING condition [,...] ] [ WINDOW window_name AS ( window_definition ) [,...] ] [ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ] [ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [,...] ] [ LIMIT { count | ALL } ] [ OFFSET start [ ROW | ROWS ] ] [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ] [ FOR { UPDATE | SHARE } [ OF table_name [,...] ] [ NOWAIT ] [...] ]

52 Query Data (FROM) Basic Form FROM Table Join Cross Join Qualified Join Inner Join Left join Right Join Full Join



55 TUGAS Buat tabel (query table) Barang Penjualan Detil Penjualan Query Insert barang (5 contoh barang) Insert data penjualan dan detil penjualan (3) Menampilkan 1 data penjualan berikut dengan detil barang yang dibeli Menampilkan total penjualan dalam satu hari (rupiah). Menampilkan barang yang memiliki stok < 5 buah

56 Fitur Lanjutan PgSQL

57 View CREATE VIEW myview AS SELECT city, temp_lo, temp_hi, prcp, date, location FROM weather, cities WHERE city = name; SELECT * FROM myview;

58 Table Relation CREATE TABLE cities ( city varchar(80) primary key, location point ); CREATE TABLE weather ( city varchar(80) REFERENCES cities(city) on delete cascade, temp_lo int, temp_hi int, prcp real, date date );


60 Transactions The essential point of a transaction is that it bundles multiple steps into a single, all-or-nothing operation

61 Transactions BEGIN UPDATE accounts SET balance = balance WHERE name = 'Alice'; UPDATE accounts SET balance = balance WHERE name = 'Bob'; COMMIT

62 Transactions BEGIN; UPDATE accounts SET balance = balance WHERE name = 'Alice'; SAVEPOINT my_savepoint; UPDATE accounts SET balance = balance WHERE name = 'Bob'; -- oops... forget that and use Wally's account ROLLBACK TO my_savepoint; UPDATE accounts SET balance = balance WHERE name = 'Wally'; COMMIT;

63 Window Function SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary; depname | empno | salary | avg develop | 11 | 5200 | develop | 7 | 4200 | develop | 9 | 4500 | develop | 8 | 6000 | develop | 10 | 5200 | personnel | 5 | 3500 | personnel | 2 | 3900 | sales | 3 | 4800 | sales | 1 | 5000 | sales | 4 | 4800 | (10 rows)

64 Inheritance CREATE TABLE cities ( name text, population real, altitude int -- (in ft) ); CREATE TABLE capitals ( state char(2) ) INHERITS (cities);

65 Inheritance SELECT name, altitude FROM cities WHERE altitude > 500; SELECT name, altitude FROM ONLY cities WHERE altitude > 500;

66 Tugas Buatlah database sederhana untuk sebuah perpustakaan jurusan. Database tersebut harus bisa. Mengelola data anggota dan koleksi Mengelola data transaksi peminjaman Memberikan laporan Jumlah total koleksi 5 mahasiswa peminjam terbanyak/bulan 10 Buku yang paling sering dipinjam/bulan Total Peminjaman koleksi/bulan Total mahasiswa yang meminjam/bulan

67 PHP & PgSQL

68 Pendahuluan PgSQL merupakan RDBMS Aplikasi membutuhkan database Aplikasi dibangun dengan menggunakan bahasa pemograman PHP…

69 Hyper Text Markup Language. HTML bukan bahasa pemrograman, HTML adalah suatu markup language. Suatu markup language berupa serangkaian markup tags. HTML menggunakan markup tags untuk mendeskripsikan halaman web. Dibantu CSS

70 HTML Tags HTML markup tag biasa disebut HTML tag. HTML tags berupa keywords oleh tanda kurung Exp : HTML tags biasanya dipakai berpasangan Start tags - end tags / opening tags - closing tags. Tag memiliki attribute HTML Document HTML document mendeskripsikan suatu web pages. HTML documents berisi HTML tags dan plain text atau text biasa.

71 HTML Tags : example

72 Standar HTML HTML 4.01 (1999) HTML 5 Apa bedanya ??

73 Pengenalan PHP PHP open-source server-side scripting language designed for Web development embedded into an HTML source document interpreted by a PHP processor module command-line interface capability can be deployed on most Web servers free of charge. Created by Rasmurf Lerdorf

74 Why PHP? Multiplatform Kompatibel dengan kebanyakan web server Support database yang luas PHP is free Mudah dipelajari

75 Overview PHP Script PHP harus berada dalam tag Variable dalam PHP Diawali dengan $ Dynamic type Operator dalam PHP As usual Commenting…

76 Overview Basic Output echo printf Input? …..

77 Control Program Pemilihan Kondisi If If … else If … else if … else Perulangan Do while While do For loop

78 Function

79 PHP & PgSQL

80 Tugas – tidak dikumpul Instalasi PgSQL Instalasi Apache & PHP Pelajari PHP Buat aplikasi CRUD data mahasiswa

81 Tabel Mahasiswa Nimvarchar(10) Namavarchar(32) Jurusanvarchar(32), enum Fakultasvarchar(32), enum Tempatlahirvarchar(32) TanggalLahirdate

82 Aplikasi Sederhana

83 Data Koleksi Perpustakaan Buat sebuah aplikasi sederhana untuk mengelola data koleksi perpustakaan. Buat database (tabel koleksi, anggota, peminjaman) Tentukan field Buat aplikasi CRUD (Create Read Update Delete) untuk koleksi Buat laporan : Statistik : Total Koleksi Total Anggota Total peminjaman/bulan Kumpulkan pada saat UAS

Download ppt "Struktur Data PostreSQL 9.2. Pengenalan PostgreSQL."

Presentasi serupa

Iklan oleh Google