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
Ad

More Related Content

What's hot (19)

Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptx
Ike Ellis
 
Demystifying data engineering
Demystifying data engineeringDemystifying data engineering
Demystifying data engineering
Thang Bui (Bob)
 
Chapter 7(documnet databse termininology) no sql for mere mortals
Chapter 7(documnet databse termininology) no sql for mere mortalsChapter 7(documnet databse termininology) no sql for mere mortals
Chapter 7(documnet databse termininology) no sql for mere mortals
nehabsairam
 
What is NoSQL and CAP Theorem
What is NoSQL and CAP TheoremWhat is NoSQL and CAP Theorem
What is NoSQL and CAP Theorem
Rahul Jain
 
Tableau on Hadoop Meet Up: Advancing from Extracts to Live Connect
Tableau on Hadoop Meet Up: Advancing from Extracts to Live ConnectTableau on Hadoop Meet Up: Advancing from Extracts to Live Connect
Tableau on Hadoop Meet Up: Advancing from Extracts to Live Connect
Remy Rosenbaum
 
60 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 201860 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 2018
Ike Ellis
 
NoSql Data Management
NoSql Data ManagementNoSql Data Management
NoSql Data Management
sameerfaizan
 
How to obtain the Cloudera Data Engineer Certification
How to obtain the Cloudera Data Engineer CertificationHow to obtain the Cloudera Data Engineer Certification
How to obtain the Cloudera Data Engineer Certification
elephantscale
 
Hadoop and IDW - When_to_use_which
Hadoop and IDW - When_to_use_whichHadoop and IDW - When_to_use_which
Hadoop and IDW - When_to_use_which
Dan TheMan
 
Star schema my sql
Star schema   my sqlStar schema   my sql
Star schema my sql
deathsubte
 
No SQL- The Future Of Data Storage
No SQL- The Future Of Data StorageNo SQL- The Future Of Data Storage
No SQL- The Future Of Data Storage
Bethmi Gunasekara
 
Chapter 5 design of keyvalue databses from nosql for mere mortals
Chapter 5 design of keyvalue databses from nosql for mere mortalsChapter 5 design of keyvalue databses from nosql for mere mortals
Chapter 5 design of keyvalue databses from nosql for mere mortals
nehabsairam
 
Database awareness
Database awarenessDatabase awareness
Database awareness
kloia
 
Introduction to NOSQL databases
Introduction to NOSQL databasesIntroduction to NOSQL databases
Introduction to NOSQL databases
Ashwani Kumar
 
5 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/25 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/2
Fabio Fumarola
 
Building next generation data warehouses
Building next generation data warehousesBuilding next generation data warehouses
Building next generation data warehouses
Alex Meadows
 
Rdbms vs. no sql
Rdbms vs. no sqlRdbms vs. no sql
Rdbms vs. no sql
Amar Jagdale
 
Eugene Polonichko "Azure Data Lake: what is it? why is it? where is it?"
Eugene Polonichko "Azure Data Lake: what is it? why is it? where is it?"Eugene Polonichko "Azure Data Lake: what is it? why is it? where is it?"
Eugene Polonichko "Azure Data Lake: what is it? why is it? where is it?"
DataConf
 
Apache Drill at ApacheCon2014
Apache Drill at ApacheCon2014Apache Drill at ApacheCon2014
Apache Drill at ApacheCon2014
Neeraja Rentachintala
 
Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptx
Ike Ellis
 
Demystifying data engineering
Demystifying data engineeringDemystifying data engineering
Demystifying data engineering
Thang Bui (Bob)
 
Chapter 7(documnet databse termininology) no sql for mere mortals
Chapter 7(documnet databse termininology) no sql for mere mortalsChapter 7(documnet databse termininology) no sql for mere mortals
Chapter 7(documnet databse termininology) no sql for mere mortals
nehabsairam
 
What is NoSQL and CAP Theorem
What is NoSQL and CAP TheoremWhat is NoSQL and CAP Theorem
What is NoSQL and CAP Theorem
Rahul Jain
 
Tableau on Hadoop Meet Up: Advancing from Extracts to Live Connect
Tableau on Hadoop Meet Up: Advancing from Extracts to Live ConnectTableau on Hadoop Meet Up: Advancing from Extracts to Live Connect
Tableau on Hadoop Meet Up: Advancing from Extracts to Live Connect
Remy Rosenbaum
 
60 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 201860 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 2018
Ike Ellis
 
NoSql Data Management
NoSql Data ManagementNoSql Data Management
NoSql Data Management
sameerfaizan
 
How to obtain the Cloudera Data Engineer Certification
How to obtain the Cloudera Data Engineer CertificationHow to obtain the Cloudera Data Engineer Certification
How to obtain the Cloudera Data Engineer Certification
elephantscale
 
Hadoop and IDW - When_to_use_which
Hadoop and IDW - When_to_use_whichHadoop and IDW - When_to_use_which
Hadoop and IDW - When_to_use_which
Dan TheMan
 
Star schema my sql
Star schema   my sqlStar schema   my sql
Star schema my sql
deathsubte
 
No SQL- The Future Of Data Storage
No SQL- The Future Of Data StorageNo SQL- The Future Of Data Storage
No SQL- The Future Of Data Storage
Bethmi Gunasekara
 
Chapter 5 design of keyvalue databses from nosql for mere mortals
Chapter 5 design of keyvalue databses from nosql for mere mortalsChapter 5 design of keyvalue databses from nosql for mere mortals
Chapter 5 design of keyvalue databses from nosql for mere mortals
nehabsairam
 
Database awareness
Database awarenessDatabase awareness
Database awareness
kloia
 
Introduction to NOSQL databases
Introduction to NOSQL databasesIntroduction to NOSQL databases
Introduction to NOSQL databases
Ashwani Kumar
 
5 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/25 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/2
Fabio Fumarola
 
Building next generation data warehouses
Building next generation data warehousesBuilding next generation data warehouses
Building next generation data warehouses
Alex Meadows
 
Eugene Polonichko "Azure Data Lake: what is it? why is it? where is it?"
Eugene Polonichko "Azure Data Lake: what is it? why is it? where is it?"Eugene Polonichko "Azure Data Lake: what is it? why is it? where is it?"
Eugene Polonichko "Azure Data Lake: what is it? why is it? where is it?"
DataConf
 

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

Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
ColdFusionConference
 
Evolution of Distributed Database Technologies in the Digital era
Evolution of Distributed Database Technologies in the Digital eraEvolution of Distributed Database Technologies in the Digital era
Evolution of Distributed Database Technologies in the Digital era
Vishal Puri
 
Pr dc 2015 sql server is cheaper than open source
Pr dc 2015 sql server is cheaper than open sourcePr dc 2015 sql server is cheaper than open source
Pr dc 2015 sql server is cheaper than open source
Terry Bunio
 
Scalable web architecture
Scalable web architectureScalable web architecture
Scalable web architecture
Kaushik Paranjape
 
Webinar: Scaling MongoDB
Webinar: Scaling MongoDBWebinar: Scaling MongoDB
Webinar: Scaling MongoDB
MongoDB
 
Conceptual vs. Logical vs. Physical Data Modeling
Conceptual vs. Logical vs. Physical Data ModelingConceptual vs. Logical vs. Physical Data Modeling
Conceptual vs. Logical vs. Physical Data Modeling
DATAVERSITY
 
SQL, NoSQL, BigData in Data Architecture
SQL, NoSQL, BigData in Data ArchitectureSQL, NoSQL, BigData in Data Architecture
SQL, NoSQL, BigData in Data Architecture
Venu Anuganti
 
How to Achieve Scale with MongoDB
How to Achieve Scale with MongoDBHow to Achieve Scale with MongoDB
How to Achieve Scale with MongoDB
MongoDB
 
Adf and ala design c sharp corner toronto chapter feb 2019 meetup nik shahriar
Adf and ala design c sharp corner toronto chapter feb 2019 meetup nik shahriarAdf and ala design c sharp corner toronto chapter feb 2019 meetup nik shahriar
Adf and ala design c sharp corner toronto chapter feb 2019 meetup nik shahriar
Nilesh Shah
 
Module 2.2 Introduction to NoSQL Databases.pptx
Module 2.2 Introduction to NoSQL Databases.pptxModule 2.2 Introduction to NoSQL Databases.pptx
Module 2.2 Introduction to NoSQL Databases.pptx
NiramayKolalle
 
Couchbase 3.0.2 d1
Couchbase 3.0.2  d1Couchbase 3.0.2  d1
Couchbase 3.0.2 d1
Sachin Kumar Kansal
 
Engineering patterns for implementing data science models on big data platforms
Engineering patterns for implementing data science models on big data platformsEngineering patterns for implementing data science models on big data platforms
Engineering patterns for implementing data science models on big data platforms
Hisham Arafat
 
NoSQLDatabases
NoSQLDatabasesNoSQLDatabases
NoSQLDatabases
Adi Challa
 
Alex mang patterns for scalability in microsoft azure application
Alex mang   patterns for scalability in microsoft azure applicationAlex mang   patterns for scalability in microsoft azure application
Alex mang patterns for scalability in microsoft azure application
Codecamp Romania
 
Future career goals in it
Future career goals in itFuture career goals in it
Future career goals in it
Hadshana Kamalanathan
 
Big Data and Data Warehousing Together with Azure Synapse Analytics (SQLBits ...
Big Data and Data Warehousing Together with Azure Synapse Analytics (SQLBits ...Big Data and Data Warehousing Together with Azure Synapse Analytics (SQLBits ...
Big Data and Data Warehousing Together with Azure Synapse Analytics (SQLBits ...
Michael Rys
 
Boosting the Performance of your Rails Apps
Boosting the Performance of your Rails AppsBoosting the Performance of your Rails Apps
Boosting the Performance of your Rails Apps
Matt Kuklinski
 
Data Lakehouse, Data Mesh, and Data Fabric (r2)
Data Lakehouse, Data Mesh, and Data Fabric (r2)Data Lakehouse, Data Mesh, and Data Fabric (r2)
Data Lakehouse, Data Mesh, and Data Fabric (r2)
James Serra
 
NoSql Brownbag
NoSql BrownbagNoSql Brownbag
NoSql Brownbag
Sandeep Kumar
 
When to Use MongoDB...and When You Should Not...
When to Use MongoDB...and When You Should Not...When to Use MongoDB...and When You Should Not...
When to Use MongoDB...and When You Should Not...
MongoDB
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
ColdFusionConference
 
Evolution of Distributed Database Technologies in the Digital era
Evolution of Distributed Database Technologies in the Digital eraEvolution of Distributed Database Technologies in the Digital era
Evolution of Distributed Database Technologies in the Digital era
Vishal Puri
 
Pr dc 2015 sql server is cheaper than open source
Pr dc 2015 sql server is cheaper than open sourcePr dc 2015 sql server is cheaper than open source
Pr dc 2015 sql server is cheaper than open source
Terry Bunio
 
Webinar: Scaling MongoDB
Webinar: Scaling MongoDBWebinar: Scaling MongoDB
Webinar: Scaling MongoDB
MongoDB
 
Conceptual vs. Logical vs. Physical Data Modeling
Conceptual vs. Logical vs. Physical Data ModelingConceptual vs. Logical vs. Physical Data Modeling
Conceptual vs. Logical vs. Physical Data Modeling
DATAVERSITY
 
SQL, NoSQL, BigData in Data Architecture
SQL, NoSQL, BigData in Data ArchitectureSQL, NoSQL, BigData in Data Architecture
SQL, NoSQL, BigData in Data Architecture
Venu Anuganti
 
How to Achieve Scale with MongoDB
How to Achieve Scale with MongoDBHow to Achieve Scale with MongoDB
How to Achieve Scale with MongoDB
MongoDB
 
Adf and ala design c sharp corner toronto chapter feb 2019 meetup nik shahriar
Adf and ala design c sharp corner toronto chapter feb 2019 meetup nik shahriarAdf and ala design c sharp corner toronto chapter feb 2019 meetup nik shahriar
Adf and ala design c sharp corner toronto chapter feb 2019 meetup nik shahriar
Nilesh Shah
 
Module 2.2 Introduction to NoSQL Databases.pptx
Module 2.2 Introduction to NoSQL Databases.pptxModule 2.2 Introduction to NoSQL Databases.pptx
Module 2.2 Introduction to NoSQL Databases.pptx
NiramayKolalle
 
Engineering patterns for implementing data science models on big data platforms
Engineering patterns for implementing data science models on big data platformsEngineering patterns for implementing data science models on big data platforms
Engineering patterns for implementing data science models on big data platforms
Hisham Arafat
 
NoSQLDatabases
NoSQLDatabasesNoSQLDatabases
NoSQLDatabases
Adi Challa
 
Alex mang patterns for scalability in microsoft azure application
Alex mang   patterns for scalability in microsoft azure applicationAlex mang   patterns for scalability in microsoft azure application
Alex mang patterns for scalability in microsoft azure application
Codecamp Romania
 
Big Data and Data Warehousing Together with Azure Synapse Analytics (SQLBits ...
Big Data and Data Warehousing Together with Azure Synapse Analytics (SQLBits ...Big Data and Data Warehousing Together with Azure Synapse Analytics (SQLBits ...
Big Data and Data Warehousing Together with Azure Synapse Analytics (SQLBits ...
Michael Rys
 
Boosting the Performance of your Rails Apps
Boosting the Performance of your Rails AppsBoosting the Performance of your Rails Apps
Boosting the Performance of your Rails Apps
Matt Kuklinski
 
Data Lakehouse, Data Mesh, and Data Fabric (r2)
Data Lakehouse, Data Mesh, and Data Fabric (r2)Data Lakehouse, Data Mesh, and Data Fabric (r2)
Data Lakehouse, Data Mesh, and Data Fabric (r2)
James Serra
 
When to Use MongoDB...and When You Should Not...
When to Use MongoDB...and When You Should Not...When to Use MongoDB...and When You Should Not...
When to Use MongoDB...and When You Should Not...
MongoDB
 
Ad

More from Nur Hidayat (7)

Develop a Software, Where to Start?
Develop a Software, Where to Start?Develop a Software, Where to Start?
Develop a Software, Where to Start?
Nur Hidayat
 
PostgreSQL Advanced Queries
PostgreSQL Advanced QueriesPostgreSQL Advanced Queries
PostgreSQL Advanced Queries
Nur Hidayat
 
Seminar Android - Pengenalan PhoneGap
Seminar Android - Pengenalan PhoneGapSeminar Android - Pengenalan PhoneGap
Seminar Android - Pengenalan PhoneGap
Nur Hidayat
 
Do IT with SQL
Do IT with SQLDo IT with SQL
Do IT with SQL
Nur Hidayat
 
How to Become Great Programmer
How to Become Great ProgrammerHow to Become Great Programmer
How to Become Great Programmer
Nur Hidayat
 
PHP Oracle
PHP OraclePHP Oracle
PHP Oracle
Nur Hidayat
 
MRI Presentation
MRI PresentationMRI Presentation
MRI Presentation
Nur Hidayat
 
Develop a Software, Where to Start?
Develop a Software, Where to Start?Develop a Software, Where to Start?
Develop a Software, Where to Start?
Nur Hidayat
 
PostgreSQL Advanced Queries
PostgreSQL Advanced QueriesPostgreSQL Advanced Queries
PostgreSQL Advanced Queries
Nur Hidayat
 
Seminar Android - Pengenalan PhoneGap
Seminar Android - Pengenalan PhoneGapSeminar Android - Pengenalan PhoneGap
Seminar Android - Pengenalan PhoneGap
Nur Hidayat
 
How to Become Great Programmer
How to Become Great ProgrammerHow to Become Great Programmer
How to Become Great Programmer
Nur Hidayat
 
MRI Presentation
MRI PresentationMRI Presentation
MRI Presentation
Nur Hidayat
 
Ad

Recently uploaded (20)

Digilocker under workingProcess Flow.pptx
Digilocker  under workingProcess Flow.pptxDigilocker  under workingProcess Flow.pptx
Digilocker under workingProcess Flow.pptx
satnamsadguru491
 
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptxmd-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
fatimalazaar2004
 
Developing Security Orchestration, Automation, and Response Applications
Developing Security Orchestration, Automation, and Response ApplicationsDeveloping Security Orchestration, Automation, and Response Applications
Developing Security Orchestration, Automation, and Response Applications
VICTOR MAESTRE RAMIREZ
 
How iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost FundsHow iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost Funds
ireneschmid345
 
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnTemplate_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
cegiver630
 
Data Analytics Overview and its applications
Data Analytics Overview and its applicationsData Analytics Overview and its applications
Data Analytics Overview and its applications
JanmejayaMishra7
 
Call illuminati Agent in uganda+256776963507/0741506136
Call illuminati Agent in uganda+256776963507/0741506136Call illuminati Agent in uganda+256776963507/0741506136
Call illuminati Agent in uganda+256776963507/0741506136
illuminati Agent uganda call+256776963507/0741506136
 
MASAkkjjkttuyrdquesjhjhjfc44dddtions.docx
MASAkkjjkttuyrdquesjhjhjfc44dddtions.docxMASAkkjjkttuyrdquesjhjhjfc44dddtions.docx
MASAkkjjkttuyrdquesjhjhjfc44dddtions.docx
santosh162
 
Chromatography_Detailed_Information.docx
Chromatography_Detailed_Information.docxChromatography_Detailed_Information.docx
Chromatography_Detailed_Information.docx
NohaSalah45
 
Minions Want to eat presentacion muy linda
Minions Want to eat presentacion muy lindaMinions Want to eat presentacion muy linda
Minions Want to eat presentacion muy linda
CarlaAndradesSoler1
 
Adobe Analytics NOAM Central User Group April 2025 Agent AI: Uncovering the S...
Adobe Analytics NOAM Central User Group April 2025 Agent AI: Uncovering the S...Adobe Analytics NOAM Central User Group April 2025 Agent AI: Uncovering the S...
Adobe Analytics NOAM Central User Group April 2025 Agent AI: Uncovering the S...
gmuir1066
 
Conic Sectionfaggavahabaayhahahahahs.pptx
Conic Sectionfaggavahabaayhahahahahs.pptxConic Sectionfaggavahabaayhahahahahs.pptx
Conic Sectionfaggavahabaayhahahahahs.pptx
taiwanesechetan
 
presentation of first program exist.pptx
presentation of first program exist.pptxpresentation of first program exist.pptx
presentation of first program exist.pptx
MajidAzeemChohan
 
i_o updated.pptx 6=₹cnjxifj,lsbd ধ and vjcjcdbgjfu n smn u cut the lb, it ও o...
i_o updated.pptx 6=₹cnjxifj,lsbd ধ and vjcjcdbgjfu n smn u cut the lb, it ও o...i_o updated.pptx 6=₹cnjxifj,lsbd ধ and vjcjcdbgjfu n smn u cut the lb, it ও o...
i_o updated.pptx 6=₹cnjxifj,lsbd ধ and vjcjcdbgjfu n smn u cut the lb, it ও o...
ggg032019
 
Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..
yuvarajreddy2002
 
Calories_Prediction_using_Linear_Regression.pptx
Calories_Prediction_using_Linear_Regression.pptxCalories_Prediction_using_Linear_Regression.pptx
Calories_Prediction_using_Linear_Regression.pptx
TijiLMAHESHWARI
 
KNN_Logistic_Regression_Presentation_Styled.pptx
KNN_Logistic_Regression_Presentation_Styled.pptxKNN_Logistic_Regression_Presentation_Styled.pptx
KNN_Logistic_Regression_Presentation_Styled.pptx
sonujha1980712
 
Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...
Pixellion
 
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptxPerencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
PareaRusan
 
PRE-NATAL GRnnnmnnnnmmOWTH seminar[1].pptx
PRE-NATAL GRnnnmnnnnmmOWTH seminar[1].pptxPRE-NATAL GRnnnmnnnnmmOWTH seminar[1].pptx
PRE-NATAL GRnnnmnnnnmmOWTH seminar[1].pptx
JayeshTaneja4
 
Digilocker under workingProcess Flow.pptx
Digilocker  under workingProcess Flow.pptxDigilocker  under workingProcess Flow.pptx
Digilocker under workingProcess Flow.pptx
satnamsadguru491
 
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptxmd-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
md-presentHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHation.pptx
fatimalazaar2004
 
Developing Security Orchestration, Automation, and Response Applications
Developing Security Orchestration, Automation, and Response ApplicationsDeveloping Security Orchestration, Automation, and Response Applications
Developing Security Orchestration, Automation, and Response Applications
VICTOR MAESTRE RAMIREZ
 
How iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost FundsHow iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost Funds
ireneschmid345
 
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnTemplate_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
cegiver630
 
Data Analytics Overview and its applications
Data Analytics Overview and its applicationsData Analytics Overview and its applications
Data Analytics Overview and its applications
JanmejayaMishra7
 
MASAkkjjkttuyrdquesjhjhjfc44dddtions.docx
MASAkkjjkttuyrdquesjhjhjfc44dddtions.docxMASAkkjjkttuyrdquesjhjhjfc44dddtions.docx
MASAkkjjkttuyrdquesjhjhjfc44dddtions.docx
santosh162
 
Chromatography_Detailed_Information.docx
Chromatography_Detailed_Information.docxChromatography_Detailed_Information.docx
Chromatography_Detailed_Information.docx
NohaSalah45
 
Minions Want to eat presentacion muy linda
Minions Want to eat presentacion muy lindaMinions Want to eat presentacion muy linda
Minions Want to eat presentacion muy linda
CarlaAndradesSoler1
 
Adobe Analytics NOAM Central User Group April 2025 Agent AI: Uncovering the S...
Adobe Analytics NOAM Central User Group April 2025 Agent AI: Uncovering the S...Adobe Analytics NOAM Central User Group April 2025 Agent AI: Uncovering the S...
Adobe Analytics NOAM Central User Group April 2025 Agent AI: Uncovering the S...
gmuir1066
 
Conic Sectionfaggavahabaayhahahahahs.pptx
Conic Sectionfaggavahabaayhahahahahs.pptxConic Sectionfaggavahabaayhahahahahs.pptx
Conic Sectionfaggavahabaayhahahahahs.pptx
taiwanesechetan
 
presentation of first program exist.pptx
presentation of first program exist.pptxpresentation of first program exist.pptx
presentation of first program exist.pptx
MajidAzeemChohan
 
i_o updated.pptx 6=₹cnjxifj,lsbd ধ and vjcjcdbgjfu n smn u cut the lb, it ও o...
i_o updated.pptx 6=₹cnjxifj,lsbd ধ and vjcjcdbgjfu n smn u cut the lb, it ও o...i_o updated.pptx 6=₹cnjxifj,lsbd ধ and vjcjcdbgjfu n smn u cut the lb, it ও o...
i_o updated.pptx 6=₹cnjxifj,lsbd ধ and vjcjcdbgjfu n smn u cut the lb, it ও o...
ggg032019
 
Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..
yuvarajreddy2002
 
Calories_Prediction_using_Linear_Regression.pptx
Calories_Prediction_using_Linear_Regression.pptxCalories_Prediction_using_Linear_Regression.pptx
Calories_Prediction_using_Linear_Regression.pptx
TijiLMAHESHWARI
 
KNN_Logistic_Regression_Presentation_Styled.pptx
KNN_Logistic_Regression_Presentation_Styled.pptxKNN_Logistic_Regression_Presentation_Styled.pptx
KNN_Logistic_Regression_Presentation_Styled.pptx
sonujha1980712
 
Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...
Pixellion
 
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptxPerencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
PareaRusan
 
PRE-NATAL GRnnnmnnnnmmOWTH seminar[1].pptx
PRE-NATAL GRnnnmnnnnmmOWTH seminar[1].pptxPRE-NATAL GRnnnmnnnnmmOWTH seminar[1].pptx
PRE-NATAL GRnnnmnnnnmmOWTH seminar[1].pptx
JayeshTaneja4
 

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 ([email protected]) Prepared for AMIK BSI Salemba
  • 3. E-Commerce Created by Nur Hidayat ([email protected]) How to Design a Good Database Social Media Prepared for AMIK BSI Salemba
  • 4. ERP Software Created by Nur Hidayat ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 5. Apa Persamaannya? Created by Nur Hidayat ([email protected]) 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 ([email protected]) 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 ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 8. Are You Ready? Created by Nur Hidayat ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 9. Characteristics of Good Database Design Created by Nur Hidayat ([email protected]) 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 ([email protected]) 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 ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 12. Database Functionality Created by Nur Hidayat ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) How to Design a Good Database NoSQL Prepared for AMIK BSI Salemba
  • 21. Created by Nur Hidayat ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 22. How to Design a Good Database Created by Nur Hidayat ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 29. Created by Nur Hidayat ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 30. Case Study: Inventory System Created by Nur Hidayat ([email protected]) 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 ([email protected]) 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 ([email protected]) 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 ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 34. Conceptual Model Created by Nur Hidayat ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 35. Logical Model Created by Nur Hidayat ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 36. Physical Model Created by Nur Hidayat ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 37. Data Retrieval using SELECT Created by Nur Hidayat ([email protected]) 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 ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 39. Created by Nur Hidayat ([email protected]) 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 ([email protected]) How to Design a Good Database AMIK BSI Salemba
  • 41. Solution Created by Nur Hidayat ([email protected]) 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 ([email protected]) How to Design a Good Database Prepared for AMIK BSI Salemba
  • 43. Created by Nur Hidayat ([email protected]) 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 ([email protected]) How to Design a Good Database Link Quesioner (wajib): http://tiny.cc/bsikuesioner AMIK BSI Salemba
  • 45. Thank You Created by Nur Hidayat ([email protected]) How to Design a Good Database AMIK BSI Salemba