SQL (Structured Query Language)

Slides:



Advertisements
Presentasi serupa
SQL  SQL adalah bahasa query baku untuk DBMS  SQL diambil sebagai bakuan sejak tahun 1992  Awalnya diterapkan pada DBMS besar seperti Oracle dan Informix,
Advertisements

Pengujian Hipotesis untuk Satu dan Dua Varians Populasi
Mata Kuliah : ALGORITMA dan STRUKTUR DATA 1.
SQL.
PEMOGRAMAN BERBASIS JARINGAN
MATA KULIAH : “LOGIKA DAN ALGORITMA”
Program Keahlian I – SI By Antonius Rachmat C, S.Kom
ORACLE Trigger Hasan Dwi Cahyono.
BAHASA QUERY TERAPAN Sub Materi : Structured Query Language
Peta Kontrol (Untuk Data Variabel)
1 Pertemuan > Desain fisik basis data Matakuliah: >/ > Tahun: > Versi: >
Memanipulasi Data1 III - Memanipulasi Data Memasukkan Data dengan INSERT: –Memasukkan nilai NULL –Menambahkan sejumlah baris data Mengubah Data dengan.
I - Mengenal Operasi Dasar SQL
Slide 3-1 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 Exercises Apa saja komponen utama.
Introduction to The Design & Analysis of Algorithms
IF-ITB/SAS/25Aug2003 IF7074 – Bagian Pertama Page 1 IF 7047 Kewirausahaan Teknologi Informasi Bagian Pertama: 1.1. Entrepreneurship, entrepreneur, dan.
Database Create-Retrieve-Update-Delete (CRUD)
PENGENALAN PL/SQL.
PROSES PADA WINDOWS Pratikum SO. Introduksi Proses 1.Program yang sedang dalam keadaan dieksekusi. 2.Unit kerja terkecil yang secara individu memiliki.
Review Operasi Matriks
Restricting and Sorting Data
Oracle Developer/2000. Developer/2000 Products FormsReportsGraphics.
Bilqis1 Pertemuan bilqis2 Sequences and Summations Deret (urutan) dan Penjumlahan.
INTEGRITY CONSTRAINTS Database System Concepts, Second Edition, Chapter 5, page 149.
Implementing an REA Model in a Relational Database
MEMORY Bhakti Yudho Suprapto,MT. berfungsi untuk memuat program dan juga sebagai tempat untuk menampung hasil proses bersifat volatile yang berarti bahwa.
Basisdata Pertanian. After completing this lesson, you should be able to do the following Identify the available group functions Describe the use of group.
1 Magister Teknik Perencanaan Universitas Tarumanagara General View On Graduate Program Urban & Real Estate Development (February 2009) Dr.-Ing. Jo Santoso.
Array
LOGO Manajemen Data Berdasarkan Komputer dengan Sistem Database.
PEMROGRAMAN PPBD (UAS) SEBELUM MELANGKAH KE TAHAP SELANJUTNYA BERDOA DULU BIAR LANCAR DAN GA EROR
Linked List dan Double Linked List
Definisi VLAN Pemisahan jaringan secara logis yang dilakukan pada switch Pada tradisional switch, dalam satu switch menunjukkan satu segmentasi LAN.
Amortization & Depresiasi
Aplikasi Manipulasi Data
By. Rita Wiryasaputra Daftar Pustaka Panduan Membuat Aplikasi Database dengan PHP, Syafii, Yogyakarta, Andi Offset, 2005 Membangun Website Dinamis dan.
1. 2 Work is defined to be the product of the magnitude of the displacement times the component of the force parallel to the displacement W = F ║ d F.
© 2009 Fakultas Teknologi Informasi Universitas Budi Luhur Jl. Ciledug Raya Petukangan Utara Jakarta Selatan Website:
SQL.
Structured Query Language (SQL)
Via Octaria Malau Transfer (Internal Transfers) Transfer (Transfers Internal) Select the account from which funds are to be transferred FROM and then select.
Web Teknologi I (MKB511C) MINGGU 3 Web Teknologi I (MKB511C) Minggu 3 Page 1 Pokok Bahasan: MySQL Tujuan Instruksional Khusus: Agar mahasiswa dapat mengetahui.
Web Teknologi I (MKB511C) Minggu 12 Page 1 MINGGU 12 Web Teknologi I (MKB511C) Pokok Bahasan: – Text processing perl-compatible regular expression/PCRE.
Lecture 2 Introduction to C# - Object Oriented Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
PRAKTIKUM BASIS DATA (4) TEKNIK INFORMATIKA UNIVERSITAS MERCU BUANA
SQL Part 3 Latar Belakang Desain Tabel Normalisasi Aljabar relasional
Jalankan script sql berikut : sekolah.sql
Pemrograman Visual II Database Management System (DBMS) Oleh: Erna Sri Hartatik, S.Kom
SQL 2. Database TRANSACTION Tabel yang terlibat : Customer berisi data pelanggan (nama, alamat, dll) OderInfo berisi info pemesanan oleh pelanggan (tgl.
Microsoft SQL Server DDL dan DML dasar
SQL.
Data Definition Language dan Data Manipulation Language
SQL (Structured Query Language) Materi Pertemuan
Data Types Data Definition Language Referential Constraint SQL Query
SQL-Aggregate dengan Fungsi GROUP, HAVING dan subQuery
SQL: DML (2) Basis Data Pertemuan 07.
BAHASA QUERY TERAPAN OLEH : HARSITI, ST.
9.3 Geometric Sequences and Series. Objective To find specified terms and the common ratio in a geometric sequence. To find the partial sum of a geometric.
Dasar query basis data dengan SQLite
DDL (DATA DEFINITION LANGUAGE) DALAM SQL
SQL (Structured Query Language)
Konsep Teknologi Informasi B
- Modul 5 - Query Lanjut 2/20/2018 7:46 PM
SQL OVERVIEW.
Structured Query Language (SQL)
SQL Data Manipulation IK203 Sistem Basis Data Pertemuan #12
SQL Part 1.
DDL (DATA DEFINITION LANGUAGE) DALAM SQL
SQL.
BAHASA BASIS DATA Data Manipulation Languange
Transcript presentasi:

SQL (Structured Query Language)

SQL Concepts of Query Basic Structure Set Operations  Aggregate Functions  Null Values  Nested Subqueries  Derived Relations  Views  Modification of the Database  Joined Relations

Tujuan Menjelaskan bahasa formal yang digunakan pada basis data relasional Menjelaskan SQL sebagai bahasa yang standar Memberikan beberapa contoh teknik pembuatan query dengan menggunakan SQL  

Pengertian Query adalah perintah-perintah untuk mengakses data pada sistem basis data SQL adalah bahasa query baku untuk DBMS  SQL diambil sebagai bakuan sejak tahun 1992  Awalnya diterapkan pada DBMS besar seperti Oracle dan Informix, sekarang juga pada DBMS berbasis PC seperti dBASE dan FoxPro.  SQL bersifat sebagai bahasa tingkat tinggi (high level). Pemakai hanya menyebutkan hasil yang diinginkan dan optimasi pelaksanaan query dilakukan oleh DBMS.

Pengertian (1) SQL dapat disisipkan ke bahasa pemrograman yang lain seperti C, Pascal, Cobol, dll. Bahasa SQL terbagi dalam dua bagian besar, yaitu: DDL (Data Definition Language) dan DML (Data Manipulation Language)  DDL mendefinisikan struktur basis data, seperti pembuatan basis data, pembuatan tabel dsbnya. Contoh: CREATE DATABASE dan CREATE TABLE.  DML merupakan bagian untuk memanipulasi basis data seperti: pengaksesan data, penghapusan, penambahan dan pengubahan data. DML juga dapat digunakan untuk melakukan komputasi data. Contoh: INSERT, DELETE, dan UPDATE.

DDL Perintah SQL untuk definisi data: CREATE untuk membentuk basis data, taable atau index ALTER untuk mengubah struktur table DROP untuk menghapus basis data, table atau index  CREATE DATABASE Untuk membentuk basis data Sintaks: CREATE DATABASE nama_database Contoh: CREATE DATABASE COMPANY  CREATE TABLE Untuk membentuk table dari basis data Untuk menyebutkan spesifikasi dan batasan atribut

DDL (1) Contoh CREATE TABLE: CREATE TABLE EMPLOYEE ( PNAME CHAR(15) NOT NULL LNAME CHAR(15) NOT NULL SSN CHAR(9) NOT NULL BDATE DATE ADDRESS CHAR(30) SEX CHAR SALARY DECIMAL(10.2) DNO CHAR(10) );

DDL (2) ALTER TABLE Digunakan untuk mengubah struktur table Contoh kasus: misalkan ingin menambahkan kolom JOB pada table EMPLOYEE dengan tipe karakter selebar 12. Perintah: ALTER TABLE EMPLOYEE ADD JOB CHAR(12);

DDL (3) CREATE INDEX Membentuk berkas index dari table Index digunakan untuk mempercepat proses pencarian Sintaks: CREATE [UNIQUE] INDEX nama_index ON nama_table(kolom1, kolom2, …. ) Contoh: CREATE INDEX EMPLOYEENDX ON EMPLOYEE(SSN)

DDL (4) Menghapus Basis Data Menghapus Table Menghapus Berkas Index DROP DATABASE Sintaks: DROP DATABASE nama_database Contoh: DROP DATABASE COMPANY Menghapus Table DROP TABLE Sintaks: DROP TABLE nama_table Contoh: DROP TABLE EMPLOYEE  Menghapus Berkas Index DROP INDEX Sintaks: DROP INDEX nama_index Contoh: DROP INDEX EMPLOYEENDX  

DML Bahasa untuk mengakses basis data Bahasa untuk mengolah basis data Bahasa untuk memanggil fungsi-fungsi agregasi Bahasa untuk melakukan query Jenis-jenis query: Sederhana Join Bertingkat  

Contoh Skema

Basic Structure SQL is based on set and relational operations with certain modifications and enhancements  A typical SQL query has the form: select A1, A2, ..., An from r1, r2, ..., rm where P A is represent attributes r is represent relations P is a predicate. This query is equivalent to the relational algebra expression. A1, A2, ..., An(P (r1 x r2 x ... x rm))  The result of an SQL query is a relation.

Query Sederhana Bentuk umum SQL SELECT [ALL|DISTINCT]   nama_kolom_kolom_tabel [INTO nama_tabel] FROM nama_nama_tabel [WHERE predikat] [GROUP BY ekspresi] [ORDER BY nama+kolom_tabel] 

Select Clause The select clause corresponds to the projection operation of the relational algebra. It is used to list the attributes desired in the result of a query.  Find the names of all branches in the loan relation select branch-name from loan In the “pure” relational algebra syntax, the query would be: branch-name(loan) An asterisk in the select clause denotes “all attributes” select * from loan NOTE: SQL does not permit the ‘-’ character in names, so you would use, for example, branch_name instead of branch-name in a real implementation. We use ‘-’ since it looks nicer! NOTE: SQL names are case insensitive, meaning you can use upper case or lower case. You may wish to use upper case in places where we use bold font

Select Clause (1) SQL allows duplicates in relations as well as in query results. To force the elimination of duplicates (menghilangkan duplikasi penampilan output yang sama) insert the keyword distinct after select. Find the names of all branches in the loan relations, and remove duplicates select distinct branch-name from loan The keyword all specifies that duplicates not be removed. select all branch-name from loan Menampilkan isi tabel customer select * from customer Menampilkan semua fname dari tabel customer select customer_name from customer

Select Clause (2) Menampilkan account number dan balance dari kantor cabang (branch_name) “Pondok Kelapa” select account_number, balance from account where branch_name = “Pondok Kelapa”; Perintah diatas dapat juga dituliskan dengan menggunakan qualified column names sebagai berikut: select account.account_number, account.balance

Select Clause (3) The select clause can contain arithmetic expressions involving the operation, +, –, * , and /, and operating on constants or attributes of tuples. The query: select loan-number, branch-name, amount 100 from loan  would return a relation which is the same as the loan relations, except that the attribute amount is multiplied by 100.

Where Clause The where clause corresponds to the selection predicate of the relational algebra. If consists of a predicate involving attributes of the relations that appear in the from clause. The find all loan number for loans made a the Perryridge branch with loan amounts greater than $1200. select loan-number from loan where branch-name = ‘Perryridge’ and amount > 1200 Comparison results can be combined using the logical connectives and, or, and not. Comparisons can be applied to results of arithmetic expressions.

Where Clause (1) SQL Includes a between comparison operator in order to simplify where clauses that specify that a value be less than or equal to some value and greater than or equal to some other value. Find the loan number of those loans with loan amounts between $90,000 and $100,000 (that is, $90,000 and $100,000) select loan-number from loan where amount between 90000 and 100000

Rename Operation The SQL allows renaming relations and attributes using the as clause: old-name as new-name Find the name, loan number and loan amount of all customers; rename the column name loan-number as loan-id. select customer-name, borrower.loan-number as loan-id, amount from borrower, loan where borrower.loan-number = loan.loan-number

String Operation SQL includes a string-matching operator for comparisons on character strings. Find the names of all customers whose street includes the substring “Main”. select customer-name from customer where customer-street like ‘%Main%’ SQL supports a variety of string operations such as concatenation (using “||”) converting from upper to lower case (and vice versa) finding string length, extracting substrings, etc.

Ordering List in alphabetic order the names of all customers having a loan in Perryridge branch select distinct customer-name from borrower, loan where borrower.loan-number = loan.loan-number and branch-name = ‘Perryridge’ order by customer-name We may specify desc for descending order or asc for ascending order, for each attribute; ascending order is the default. E.g. order by customer-name desc

Aggregate Function These functions operate on the multiset of values of a column of a relation, and return a value avg: average value min: minimum value max: maximum value sum: sum of values count: number of values

Aggregate Function (1) Find the average account balance at the Perryridge branch. select avg (balance) from account where branch-name = ‘Perryridge’ Find the number of tuples in the customer relation. select count (*) from customer Find the number of depositors in the bank. select count (distinct customer-name) from depositor

Aggregate Function - Group By Find the number of depositors for each branch. select branch-name, count (distinct customer-name) from depositor, account where depositor.account-number = account.account-number group by branch-name  Note: Attributes in select clause outside of aggregate functions must appear in group by list

Aggregate Function – having clause Find the names of all branches where the average account balance is more than $1,200. select branch-name, avg (balance) from account group by branch-name having avg (balance) > 1200 Note: predicates in the having clause are applied after the formation of groups whereas predicates in the where clause are applied before forming groups

SELAMAT BELAJAR ...