SlideShare a Scribd company logo
Database Design
How to Design a Good Database
for Your Great Application
Seminar Program Studi Manajeman Informatika
18 April 2018 - AMIK BSI Kampus Salemba
About Me
• Editor PojokProgrammer.net
• Writers welcome!
• CEO BiruniLabs
• Trainers welcome!
• CEO Cronos Studio
• Developers welcome!
• Pegiat Komunitas
• PHP Indonesia
• Drupal Indonesia
• VB.Net Indonesia
How to Design a Good Database
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
Prepared for
AMIK BSI Salemba
E-Commerce
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
Social Media
Prepared for
AMIK BSI Salemba
ERP Software
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Apa Persamaannya?
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Good Design Matters
• Data are foundation of your application.
• A well designed database is easy to understand.
• A well designed database performs fast and efficient.
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
Poorly
Designed
Database
Poorly
Designed
Application
Low
Performance &
Chaotic Data
Difficult to
Maintain &
Enhance
AMIK BSI Salemba
Agenda
•Characteristics of Good Database Design
•How to Design a Good Database
•Case Study: Inventory System
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Are You Ready?
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Characteristics of Good
Database Design
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Things To Consider
• What Functionality is Needed from the Database?
• Break Your Data Into Logical Pieces
• Avoid Data Separated by Separators
• Centralize Name Value Table Design
• Self-reference PK And FK For Unlimited Hierarchical Data
• Database Design Tips
• Relational vs. NoSQL Databases
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Database Functionality
• Transactional (OLTP): Write intensive application. Your end
user is more interested in CRUD, i.e., creating, reading,
updating, and deleting records.
• Analytical (OLAP): Read intensive applications. Your end user
is more interested in analysis, reporting, forecasting, etc.
These kinds of databases have a less number of inserts and
updates. The main intention here is to fetch and analyze data
as fast as possible.
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Database Functionality
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Break Your Data Into Logical Pieces
• This rule is from the first rule of 1st normal form.
• If your queries are using too many string parsing functions
like substring, charindex, etc., then probably this rule needs
to be applied.
• Common Example, Name and Address Field
• Break this field into further logical pieces so that we can
write clean and optimal queries.
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
• This rule is from the second
rule of 1st normal form.
• Data stuffed with separators
need special attention and
should be to moved to a
different table
• Link them with keys for better
management.
Avoid Data with Separators
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
Prepared for
AMIK BSI Salemba
• Name and value tables
contains key and some data
associated with the key.
• Lookup Tables
• Differentiating the data
using a type field.
• Adding new type of does not
require to create new table.
Centralize Name Value Table Design
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
Prepared for
AMIK BSI Salemba
• Data with unlimited parent child
hierarchy.
• Consider a multi-level marketing
scenario where a sales person can
have multiple sales people below
them.
• Using a self-referencing primary key
and foreign key will simplify
database design.
Self-reference for Hierarchical Data
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
Prepared for
AMIK BSI Salemba
Database Design Tips
• Use English for table and field naming, all plural or all singular
• Use well defined and consistent names for tables and columns (e.g.
School, StudentCourse, CourseID ...)
• Don’t use unnecessary prefixes or suffixes for table names (i.e. use
School instead of TblSchool, SchoolTable etc.).
• Keep passwords as encrypted or hashed for security. Decrypt them in
application when required.
• Use integer id fields for all tables. If id is not required for the time
being, it may be required in the future (for association
tables, indexing ...).
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Database Design Tips
• Choose columns with the integer data type (or its variants) for
indexing. varchar column indexing will cause performance problems.
• Use constraints (foreign key, check, not null ...) for data integrity.
Don’t give whole control to application code.
• Lack of database documentation is evil. Document your database
design with ER schemas and instructions. Also write comment lines
for your triggers, stored procedures and other scripts.
• Use indexes for frequently used queries on big tables.
• Place Image and blob data in separate tables.
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Relational vs. NoSQL Databases
• Not every database fits every business need.
• Many companies rely on both relational and non-relational
databases for different tasks.
• NoSQL databases gained popularity for their speed and
scalability.
• There are still situations in which a highly structured SQL
database more preferable
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
• You need ACID compliancy
(Atomicity, Consistency,
Isolation, Durability).
• Your data is structured and
unchanging
• Standards-based proven
technology with good
developer experience and
support
• Storing large volumes of
data without structure.
• Using cloud computing and
storage. Easily spread data
across servers
• Simpler or looser project
objectives
• Rapid development, able to
start coding immediately
RDBMS
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
NoSQL
Prepared for
AMIK BSI Salemba
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
How to Design
a Good Database
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Concepts to Master
• Conceptual Model
• Logical Model
• Physical Model
• Natural Key vs Surrogate Key
• Normalisasi vs. Denormalisasi
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
• Identifikasikan semua
entitas (entity) yang
terlibat dalam sistem
yang ingin
dikembangkan.
• Buat Conceptual Model
berupa relasi antar
entitas tersebut.
• Gambarkan hanya relasi
antar entitas tersebut,
tidak termasuk atribut
dari entitas tersebut.
Conceptual Model
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
Prepared for
AMIK BSI Salemba
• Tambahkan
attributes yang
diperlukan oleh
setiap entitas.
• Definisikan atribut
yang bertindak
sebagai PK, namun
kita tidak perlu
mendefinisikan FK.
Logical Model
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
Prepared for
AMIK BSI Salemba
• Tentukan tipe data
dari masing-masing
kolom sesuai dengan
RDBMS yang kita
pilih.
• Pemetakan relasi FK
serta buat associative
table untuk relasi
many-to-many.
Physical Model
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
Prepared for
AMIK BSI Salemba
Natural Key vs. Surrogate Key
• Ada kalanya sebuah tabel sudah memiliki kolom yang
nilainya unik untuk setiap baris (row)
• Kolom seperti ini disebut Natural Key, dan bisa kita jadikan
sebagai Primary Key.
• Best-practice tetap menambahkan Surrogate Key dan
menjadikannya sebagai Primary Key.
• Surrogate Key di-generate oleh database, biasanya berupa
field integer yang nilainya auto increment.
• Natural Key yang ada cukup sebagai unique index.
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Normalisasi vs. Denormalisasi
• Normalization must be used as required, to optimize the
performance.
• Under-normalization will cause excessive repetition of data.
• Over-normalization will cause excessive joins across too
many tables.
• Both of them will get worse performance.
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Case Study:
Inventory System
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Things To Do
• Requirements
• Conceptual Model
• Logical Model
• Physical Model
• Change Your Mindset
• SQL Rule of Thumb
• Data Retrieval using SELECT
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Requirements
• Perusahaan ada di beberapa lokasi.
• Setiap lokasi ada beberapa warehouse.
• Sistem harus mengetahui stok barang per warehouse.
• Ada beberapa jenis barang tersedia, misalkan raw material
dan finished goods.
• Sistem harus mencatat semua transaksi barang masuk.
• Sistem harus mencatat semua transaksi barang keluar.
• Sistem harus dapat mengeluarkan Laporan Kartu Stok.
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
We Will Need
• Locations entity (data lokasi)
• Warehouse entity (data gudang)
• Items entity (data barang)
• Item_Types entity (data jenis barang)
• Transactions entity (data transaksi)
• Transaction_Types entity (data jenis transaksi)
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Conceptual Model
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Logical Model
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Physical Model
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Data Retrieval using SELECT
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
SQL Rule of Thumb
• Use single SQL statement whenever possible
• Use PL/SQL or Stored Procedure
• Use Java (or other programming language)
• Rethink why you want to do it (refine your approach)
From Tom Kyte (Oracle Evangelist)
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Change Your Mindset
• Apa yang akan kalian lakukan jika mendapatkan tugas seperti
di bawah ini
• Tampilkan angka 1 sampai dengan 100, namun…
• setiap kelipatan 3 ubah angkanya menjadi kata Rumah,
• setiap kelipatan 5 ubah angkanya menjadi kata Sakit, dan
• setiap kelipatan 15 ubah angkanya menjadi kata Rumah Sakit.
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Solution
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
SELECT t.id AS trans_id, t.trans_code AS trans_code
, t.trans_date AS trans_date, a.id AS detail_id, a.item_id
, trim(concat(t.remarks,' - ',a.remarks)) AS remarks,
b.code AS item_code, b.name AS item_name
, CASE
WHEN t.type_id=1 THEN a.quantity
WHEN t.type_id=2 THEN -a.quantity
ELSE 0 END
AS quantity
, @sal := @sal + CASE
WHEN t.type_id=1 THEN a.quantity
WHEN t.type_id=2 THEN -a.quantity
ELSE 0 END
AS saldo
FROM transactions t
JOIN transaction_details a ON t.id = a.trans_id
JOIN items b ON a.item_id = b.id
JOIN ( SELECT @sal:=0 ) v
WHERE b.id = :id
ORDER BY t.trans_date, t.id, a.id
Query for Stock Card
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
Prepared for
AMIK BSI Salemba
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba
Contact Us
• Telegram: @hidayat365
• PHP Indonesia for Student https://t.me/PHPIDforStudent
• MySQL Indonesia https://t.me/mysqlid
• Github: https://github.com/hidayat365
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database
Link Quesioner (wajib):
http://tiny.cc/bsikuesioner
AMIK BSI Salemba
Thank You
Created by Nur Hidayat
(nur.hidayat@cronosstudio.id)
How to Design a Good Database AMIK BSI Salemba

More Related Content

PPTX
How to Design a Good Database
PDF
Do It With SQL - Journey to the Center of Database Worlds
PPTX
How to Survive as a Data Architect in a Polyglot Database World
PPTX
Karen's Favourite Features of SQL Server 2016
PPT
KnowIT, semantic informatics knowledge base
PDF
Big Challenges in Data Modeling: NoSQL and Data Modeling
PPTX
7 Databases in 70 minutes
PDF
Data Engineering Basics
How to Design a Good Database
Do It With SQL - Journey to the Center of Database Worlds
How to Survive as a Data Architect in a Polyglot Database World
Karen's Favourite Features of SQL Server 2016
KnowIT, semantic informatics knowledge base
Big Challenges in Data Modeling: NoSQL and Data Modeling
7 Databases in 70 minutes
Data Engineering Basics

What's hot (19)

PPTX
Build a modern data platform.pptx
PPTX
Demystifying data engineering
PPTX
Chapter 7(documnet databse termininology) no sql for mere mortals
PPTX
What is NoSQL and CAP Theorem
PPTX
Tableau on Hadoop Meet Up: Advancing from Extracts to Live Connect
PPTX
60 reporting tips in 60 minutes - SQLBits 2018
PPTX
NoSql Data Management
PDF
How to obtain the Cloudera Data Engineer Certification
PDF
Hadoop and IDW - When_to_use_which
PPT
Star schema my sql
PPTX
No SQL- The Future Of Data Storage
PPTX
Chapter 5 design of keyvalue databses from nosql for mere mortals
PPTX
Database awareness
PPTX
Introduction to NOSQL databases
PPT
5 Data Modeling for NoSQL 1/2
ODP
Building next generation data warehouses
PPTX
Rdbms vs. no sql
PPTX
Eugene Polonichko "Azure Data Lake: what is it? why is it? where is it?"
PPTX
Apache Drill at ApacheCon2014
Build a modern data platform.pptx
Demystifying data engineering
Chapter 7(documnet databse termininology) no sql for mere mortals
What is NoSQL and CAP Theorem
Tableau on Hadoop Meet Up: Advancing from Extracts to Live Connect
60 reporting tips in 60 minutes - SQLBits 2018
NoSql Data Management
How to obtain the Cloudera Data Engineer Certification
Hadoop and IDW - When_to_use_which
Star schema my sql
No SQL- The Future Of Data Storage
Chapter 5 design of keyvalue databses from nosql for mere mortals
Database awareness
Introduction to NOSQL databases
5 Data Modeling for NoSQL 1/2
Building next generation data warehouses
Rdbms vs. no sql
Eugene Polonichko "Azure Data Lake: what is it? why is it? where is it?"
Apache Drill at ApacheCon2014
Ad

Similar to How to Design a Good Database for Your Application (20)

PDF
Building better SQL Server Databases
PDF
Evolution of Distributed Database Technologies in the Digital era
PDF
Pr dc 2015 sql server is cheaper than open source
PDF
Scalable web architecture
PPTX
Webinar: Scaling MongoDB
PDF
Conceptual vs. Logical vs. Physical Data Modeling
PPT
SQL, NoSQL, BigData in Data Architecture
PPTX
How to Achieve Scale with MongoDB
PDF
Adf and ala design c sharp corner toronto chapter feb 2019 meetup nik shahriar
PPTX
Module 2.2 Introduction to NoSQL Databases.pptx
PDF
Couchbase 3.0.2 d1
PPTX
Engineering patterns for implementing data science models on big data platforms
PPTX
NoSQLDatabases
PDF
Alex mang patterns for scalability in microsoft azure application
PPTX
Future career goals in it
PPTX
Big Data and Data Warehousing Together with Azure Synapse Analytics (SQLBits ...
PPTX
Boosting the Performance of your Rails Apps
PPTX
Data Lakehouse, Data Mesh, and Data Fabric (r2)
PPTX
NoSql Brownbag
PPTX
When to Use MongoDB...and When You Should Not...
Building better SQL Server Databases
Evolution of Distributed Database Technologies in the Digital era
Pr dc 2015 sql server is cheaper than open source
Scalable web architecture
Webinar: Scaling MongoDB
Conceptual vs. Logical vs. Physical Data Modeling
SQL, NoSQL, BigData in Data Architecture
How to Achieve Scale with MongoDB
Adf and ala design c sharp corner toronto chapter feb 2019 meetup nik shahriar
Module 2.2 Introduction to NoSQL Databases.pptx
Couchbase 3.0.2 d1
Engineering patterns for implementing data science models on big data platforms
NoSQLDatabases
Alex mang patterns for scalability in microsoft azure application
Future career goals in it
Big Data and Data Warehousing Together with Azure Synapse Analytics (SQLBits ...
Boosting the Performance of your Rails Apps
Data Lakehouse, Data Mesh, and Data Fabric (r2)
NoSql Brownbag
When to Use MongoDB...and When You Should Not...
Ad

More from Nur Hidayat (7)

PDF
Develop a Software, Where to Start?
PDF
PostgreSQL Advanced Queries
PPTX
Seminar Android - Pengenalan PhoneGap
PPTX
Do IT with SQL
PPTX
How to Become Great Programmer
PPTX
PHP Oracle
PPTX
MRI Presentation
Develop a Software, Where to Start?
PostgreSQL Advanced Queries
Seminar Android - Pengenalan PhoneGap
Do IT with SQL
How to Become Great Programmer
PHP Oracle
MRI Presentation

Recently uploaded (20)

PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PDF
Lecture1 pattern recognition............
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPTX
1_Introduction to advance data techniques.pptx
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
IB Computer Science - Internal Assessment.pptx
PPTX
STERILIZATION AND DISINFECTION-1.ppthhhbx
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PDF
annual-report-2024-2025 original latest.
PDF
Introduction to Data Science and Data Analysis
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPTX
Supervised vs unsupervised machine learning algorithms
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
Computer network topology notes for revision
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Clinical guidelines as a resource for EBP(1).pdf
Acceptance and paychological effects of mandatory extra coach I classes.pptx
Lecture1 pattern recognition............
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
1_Introduction to advance data techniques.pptx
IBA_Chapter_11_Slides_Final_Accessible.pptx
IB Computer Science - Internal Assessment.pptx
STERILIZATION AND DISINFECTION-1.ppthhhbx
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
Introduction-to-Cloud-ComputingFinal.pptx
annual-report-2024-2025 original latest.
Introduction to Data Science and Data Analysis
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Supervised vs unsupervised machine learning algorithms
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Computer network topology notes for revision
Galatica Smart Energy Infrastructure Startup Pitch Deck
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb

How to Design a Good Database for Your Application

  • 1. Database Design How to Design a Good Database for Your Great Application Seminar Program Studi Manajeman Informatika 18 April 2018 - AMIK BSI Kampus Salemba
  • 2. About Me • Editor PojokProgrammer.net • Writers welcome! • CEO BiruniLabs • Trainers welcome! • CEO Cronos Studio • Developers welcome! • Pegiat Komunitas • PHP Indonesia • Drupal Indonesia • VB.Net Indonesia How to Design a Good Database Created by Nur Hidayat (nur.hidayat@cronosstudio.id) Prepared for AMIK BSI Salemba
  • 3. E-Commerce Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database Social Media Prepared for AMIK BSI Salemba
  • 4. ERP Software Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 5. Apa Persamaannya? Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 6. Good Design Matters • Data are foundation of your application. • A well designed database is easy to understand. • A well designed database performs fast and efficient. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database Poorly Designed Database Poorly Designed Application Low Performance & Chaotic Data Difficult to Maintain & Enhance AMIK BSI Salemba
  • 7. Agenda •Characteristics of Good Database Design •How to Design a Good Database •Case Study: Inventory System Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 8. Are You Ready? Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 9. Characteristics of Good Database Design Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 10. Things To Consider • What Functionality is Needed from the Database? • Break Your Data Into Logical Pieces • Avoid Data Separated by Separators • Centralize Name Value Table Design • Self-reference PK And FK For Unlimited Hierarchical Data • Database Design Tips • Relational vs. NoSQL Databases Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 11. Database Functionality • Transactional (OLTP): Write intensive application. Your end user is more interested in CRUD, i.e., creating, reading, updating, and deleting records. • Analytical (OLAP): Read intensive applications. Your end user is more interested in analysis, reporting, forecasting, etc. These kinds of databases have a less number of inserts and updates. The main intention here is to fetch and analyze data as fast as possible. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 12. Database Functionality Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 13. Break Your Data Into Logical Pieces • This rule is from the first rule of 1st normal form. • If your queries are using too many string parsing functions like substring, charindex, etc., then probably this rule needs to be applied. • Common Example, Name and Address Field • Break this field into further logical pieces so that we can write clean and optimal queries. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 14. • This rule is from the second rule of 1st normal form. • Data stuffed with separators need special attention and should be to moved to a different table • Link them with keys for better management. Avoid Data with Separators Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database Prepared for AMIK BSI Salemba
  • 15. • Name and value tables contains key and some data associated with the key. • Lookup Tables • Differentiating the data using a type field. • Adding new type of does not require to create new table. Centralize Name Value Table Design Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database Prepared for AMIK BSI Salemba
  • 16. • Data with unlimited parent child hierarchy. • Consider a multi-level marketing scenario where a sales person can have multiple sales people below them. • Using a self-referencing primary key and foreign key will simplify database design. Self-reference for Hierarchical Data Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database Prepared for AMIK BSI Salemba
  • 17. Database Design Tips • Use English for table and field naming, all plural or all singular • Use well defined and consistent names for tables and columns (e.g. School, StudentCourse, CourseID ...) • Don’t use unnecessary prefixes or suffixes for table names (i.e. use School instead of TblSchool, SchoolTable etc.). • Keep passwords as encrypted or hashed for security. Decrypt them in application when required. • Use integer id fields for all tables. If id is not required for the time being, it may be required in the future (for association tables, indexing ...). Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 18. Database Design Tips • Choose columns with the integer data type (or its variants) for indexing. varchar column indexing will cause performance problems. • Use constraints (foreign key, check, not null ...) for data integrity. Don’t give whole control to application code. • Lack of database documentation is evil. Document your database design with ER schemas and instructions. Also write comment lines for your triggers, stored procedures and other scripts. • Use indexes for frequently used queries on big tables. • Place Image and blob data in separate tables. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 19. Relational vs. NoSQL Databases • Not every database fits every business need. • Many companies rely on both relational and non-relational databases for different tasks. • NoSQL databases gained popularity for their speed and scalability. • There are still situations in which a highly structured SQL database more preferable Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 20. • You need ACID compliancy (Atomicity, Consistency, Isolation, Durability). • Your data is structured and unchanging • Standards-based proven technology with good developer experience and support • Storing large volumes of data without structure. • Using cloud computing and storage. Easily spread data across servers • Simpler or looser project objectives • Rapid development, able to start coding immediately RDBMS Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database NoSQL Prepared for AMIK BSI Salemba
  • 21. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 22. How to Design a Good Database Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 23. Concepts to Master • Conceptual Model • Logical Model • Physical Model • Natural Key vs Surrogate Key • Normalisasi vs. Denormalisasi Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 24. • Identifikasikan semua entitas (entity) yang terlibat dalam sistem yang ingin dikembangkan. • Buat Conceptual Model berupa relasi antar entitas tersebut. • Gambarkan hanya relasi antar entitas tersebut, tidak termasuk atribut dari entitas tersebut. Conceptual Model Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database Prepared for AMIK BSI Salemba
  • 25. • Tambahkan attributes yang diperlukan oleh setiap entitas. • Definisikan atribut yang bertindak sebagai PK, namun kita tidak perlu mendefinisikan FK. Logical Model Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database Prepared for AMIK BSI Salemba
  • 26. • Tentukan tipe data dari masing-masing kolom sesuai dengan RDBMS yang kita pilih. • Pemetakan relasi FK serta buat associative table untuk relasi many-to-many. Physical Model Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database Prepared for AMIK BSI Salemba
  • 27. Natural Key vs. Surrogate Key • Ada kalanya sebuah tabel sudah memiliki kolom yang nilainya unik untuk setiap baris (row) • Kolom seperti ini disebut Natural Key, dan bisa kita jadikan sebagai Primary Key. • Best-practice tetap menambahkan Surrogate Key dan menjadikannya sebagai Primary Key. • Surrogate Key di-generate oleh database, biasanya berupa field integer yang nilainya auto increment. • Natural Key yang ada cukup sebagai unique index. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 28. Normalisasi vs. Denormalisasi • Normalization must be used as required, to optimize the performance. • Under-normalization will cause excessive repetition of data. • Over-normalization will cause excessive joins across too many tables. • Both of them will get worse performance. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 29. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 30. Case Study: Inventory System Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 31. Things To Do • Requirements • Conceptual Model • Logical Model • Physical Model • Change Your Mindset • SQL Rule of Thumb • Data Retrieval using SELECT Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 32. Requirements • Perusahaan ada di beberapa lokasi. • Setiap lokasi ada beberapa warehouse. • Sistem harus mengetahui stok barang per warehouse. • Ada beberapa jenis barang tersedia, misalkan raw material dan finished goods. • Sistem harus mencatat semua transaksi barang masuk. • Sistem harus mencatat semua transaksi barang keluar. • Sistem harus dapat mengeluarkan Laporan Kartu Stok. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 33. We Will Need • Locations entity (data lokasi) • Warehouse entity (data gudang) • Items entity (data barang) • Item_Types entity (data jenis barang) • Transactions entity (data transaksi) • Transaction_Types entity (data jenis transaksi) Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 34. Conceptual Model Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 35. Logical Model Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 36. Physical Model Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 37. Data Retrieval using SELECT Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 38. SQL Rule of Thumb • Use single SQL statement whenever possible • Use PL/SQL or Stored Procedure • Use Java (or other programming language) • Rethink why you want to do it (refine your approach) From Tom Kyte (Oracle Evangelist) Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 39. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 40. Change Your Mindset • Apa yang akan kalian lakukan jika mendapatkan tugas seperti di bawah ini • Tampilkan angka 1 sampai dengan 100, namun… • setiap kelipatan 3 ubah angkanya menjadi kata Rumah, • setiap kelipatan 5 ubah angkanya menjadi kata Sakit, dan • setiap kelipatan 15 ubah angkanya menjadi kata Rumah Sakit. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 41. Solution Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 42. SELECT t.id AS trans_id, t.trans_code AS trans_code , t.trans_date AS trans_date, a.id AS detail_id, a.item_id , trim(concat(t.remarks,' - ',a.remarks)) AS remarks, b.code AS item_code, b.name AS item_name , CASE WHEN t.type_id=1 THEN a.quantity WHEN t.type_id=2 THEN -a.quantity ELSE 0 END AS quantity , @sal := @sal + CASE WHEN t.type_id=1 THEN a.quantity WHEN t.type_id=2 THEN -a.quantity ELSE 0 END AS saldo FROM transactions t JOIN transaction_details a ON t.id = a.trans_id JOIN items b ON a.item_id = b.id JOIN ( SELECT @sal:=0 ) v WHERE b.id = :id ORDER BY t.trans_date, t.id, a.id Query for Stock Card Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database Prepared for AMIK BSI Salemba
  • 43. Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba
  • 44. Contact Us • Telegram: @hidayat365 • PHP Indonesia for Student https://t.me/PHPIDforStudent • MySQL Indonesia https://t.me/mysqlid • Github: https://github.com/hidayat365 Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database Link Quesioner (wajib): http://tiny.cc/bsikuesioner AMIK BSI Salemba
  • 45. Thank You Created by Nur Hidayat (nur.hidayat@cronosstudio.id) How to Design a Good Database AMIK BSI Salemba