sql ( structured query language)

10
SQL (STRUCTURED QUERY LANGUAGE) DML

Upload: gail-huber

Post on 30-Dec-2015

23 views

Category:

Documents


0 download

DESCRIPTION

SQL ( Structured Query Language). 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 Penggunaan Skema. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: SQL  ( Structured Query Language)

SQL (STRUCTURED QUERY LANGUAGE)

DML

Page 2: SQL  ( Structured Query Language)

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

Page 3: SQL  ( Structured Query Language)

CONTOH PENGGUNAAN SKEMA

Page 4: SQL  ( Structured Query Language)

SQL is based on set and relational operations with certain modifications and enhancements

A typical SQL query has the form:select A1, A2, ..., Anfrom r1, r2, ..., rmwhere P

Ais represent attributes ris represent relations P is a predicate.

This query is equivalent to the relational algebra expression.

ÕA1, A2, ..., An(sP (r1 x r2 x ... x rm)) The result of an SQL query is a relation.

Page 5: SQL  ( Structured Query Language)

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]

Page 6: SQL  ( Structured Query Language)

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 relationselect branch-namefrom 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, forexample, 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

Page 7: SQL  ( Structured Query Language)

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

Page 8: SQL  ( Structured Query Language)

Menampilkan account number dan balance dari kantor cabang (branch_name) “Pondok Kelapa”

select account_number, balancefrom accountwhere branch_name = “Pondok Kelapa”;

Perintah diatas dapat juga dituliskan dengan menggunakan qualified column names sebagai berikut:

select account.account_number,account.balancefrom accountwhere branch_name = “Pondok Kelapa”;

Page 9: SQL  ( Structured Query Language)

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 * 100from loan

would return a relation which is the same as the loan

would return a relation which is the same as the loan relations, except

that the attribute amount is multiplied by 100.

Page 10: SQL  ( Structured Query Language)