Upload presentasi
Presentasi sedang didownload. Silahkan tunggu
Diterbitkan olehAdjie Screamo Telah diubah "9 tahun yang lalu
1
PRAKTIKUM 3 PEMROGRAMAN BASIS DATA
2
Menghapus baris Deleting rows- DELETE FROM Use the DELELE FROM command to delete row(s) from a table, with the following syntax: -- Delete all rows from the table. Use with extreme care! Records are NOT recoverable!!! DELETE FROM tableName -- Delete only row(s) that meets the criteria DELETE FROM tableName WHERE criteria
3
contoh mysql> DELETE FROM products WHERE name LIKE 'Pencil%'; mysql> SELECT * FROM products;
4
Beware that "DELETE FROM tableName" without a WHERE clause deletes ALL records from the table. Even with a WHERE clause, you might have deleted some records unintentionally. It is always advisable to issue a SELECT command with the same WHERE clause to check the result set before issuing the DELETE (and UPDATE).
5
Loading/exporting data from/to a text file There are several ways to add data into the database: (a) manually issue the INSERT commands; (b) run the INSERT commands from a script; (c) load raw data from a file using LOAD DATA or via mysqlimport utility.
6
LOAD DATA LOCAL INFILE... INTO TABLE... Besides using INSERT commands to insert rows, you could keep your raw data in a text file, and load them into the table via the LOAD DATA command. For example, create the following text file called "produk_in.csv", where the values are separated by ','. The file extension of ".csv" stands for Comma-Separated Values text file. \N,PENC,Pensil 3B,500,3000 \N,PENC,Pensil 4B,300,3500 \N,PENC,Pensil 5B,800,3750 \N,PENC,Pensil 6B,400,4000
7
mysql> LOAD DATA LOCAL INFILE 'd:/produk_in.csv' INTO TABLE produk COLUMNS TERMINATED BY ',' LINES TERMINATED BY '\r\n';
8
Notes: You need to provide the path (absolute or relative) and the filename. Use Unix-style forward-slash '/' as the directory separator, instead of Windows-style back-slash '\'. The default line delimiter (or end-of-line) is '\n' (Unix-style). If the text file is prepared in Windows, you need to include LINES TERMINATED BY '\r\n'. For Mac, use LINES TERMINATED BY '\r'. The default column delimiter is "tab" (in a so-called TSV file - Tab-Separated Values). If you use another delimiter, e.g. ',', include COLUMNS TERMINATED BY ','. You must use \N (back-slash + uppercase 'N') for NULL.
9
Select …into outfile … Lihat hasil file yang dibuat pada d:/…
10
More than one tables
11
One to many relationship Masing-masing produk memiliki satu suplier, dan setiap suplier menyuplai minimal nol atau lebih produk. Buat tabel suplier dengan atribut id_supl(int), nama_supl (varchar(3)), dan telp (char(8)) Id_supl (int)Nama_supl(varchar)Phone (char(8)) 501Perusahaan ABC88882222 502Perusahaan XYZ77773333 503Perusahaan KLM77772222
12
Tabel Id_produkKode_produkNama_produkJumlahHargaId_supl 1001PENPulpen merah5003500501 1002PENPulpen Hitam10003500501 1003PENPulpen biru10003500501 1004PENCPensil 6B4004000502 1005PENCPensil 5B8003750502 1006PENCPensil 4B3003500503 1007PENCPensil 3B5003000503
13
Buat tabel suplier
14
Masukkan data suplier
15
Buat kolom id_suplier pada tabel produk
16
Tambahkan id_suplier sebagai foreign key pada tabel produk
17
Ganti id supl pada masing-masing produk
18
Select with Join SELECT command can be used to query and join data from two related tables. For example, to list the product's name (in products table) and supplier's name (in suppliers table), we could join the two table via the two common supplierID columns
20
Join via where clause (legacy and not recommended)
21
Gunakan alias ‘AS’ untuk menampilkan nama kolom
22
Many to Many Setiap produk dapat disuplai oleh banyak suplier dan setiap suplier dapat menyuplai banyak produk. Buat sebuah tabel baru, sebagai tabel penghubung (junction/join tabel) yang diberi nama tabel suplier_produk.
23
Tabel suplier_produk Id_produk (foreign key)Id_supl (foreign key) 1001501 1002501 1003501 1004502 1005503 1006503 1007503
26
Masukkan nilai untuk suplier_produk
27
Hapus kolom id_supl pada tabel produk, karena ini hanya berlaku pada one to many relationship. Sebelum menghapus kolom id_supl, kita hilangkan dulu foreign key yang ada pada column tersebut. Karena key merupakan constraint yang diberikan oleh sistem, maka kita masuk ke sistem databasenya.
33
One to one relationship
34
Backup The syntax for the mysqldump program is as follows: -- Dump selected databases with --databases option > mysqldump -u username -p --databases database1Name [database2Name...] > backupFile.sql -- Dump all databases in the server with --all-databases option, except mysql.user table (for security) > mysqldump -u root -p --all-databases --ignore-table=mysql.user > backupServer.sql -- Dump all the tables of a particular database > mysqldump -u username -p databaseName > backupFile.sql -- Dump selected tables of a particular database > mysqldump - u username -p databaseName table1Name [table2Name...] > backupFile.sql
35
Backup Keluar dulu ke bin Lihat hasilny pada d:/projek
Presentasi serupa
© 2024 SlidePlayer.info Inc.
All rights reserved.