SlideShare a Scribd company logo
1 of 14
Relational DB Design
Vijay
Kalangi
• Plan your db
• What information must be stored?
• In which tables
• In what form?
• Goal of db design
• Minimum redundancy
• Integrity (Relational and data)
• Performance
• Normalization!
• minimizes redundancy
• no anomalies
• update - same data in two places
• delete - only one record
• insert - inserting one attribute requires inserting
additional info.
• HTML and browser as a thin client
• Page based architecture
• Distribution problem solved!
• Keys
• unique
• primary
• foreign
• composite
• candidate
• Relations
• one-one
• one-many
• many-many
• Joins
• inner join - only when there is a match
• left join - all from first table even if there are no
matches in second table
• right join - all from 2nd table even if there are no
matches in first table
• outer join - An OUTER JOIN retrieves data from both
tables, when there are no matching values in the
tables.The end result will be a summation of all rows
in both tables.
• Example
SELECT * FROM product_prd INNER JOIN
category_ctg ON product_prd.idctg_prd =
category_ctg.id_ctg
• Best practices
• Comment
• don’t store binary data
• same column in diff. tables should have same
datatype (ex: foreign key)
• no select *
• when running an insert action query, use the
columns list into which to insert instead of the
table name
• Why naming convention
• Clear structure
• Everyone is on same page
• Maintenance
• use project name as the name of database
• prefix the db name with the name of environment - proto_DB live_DB etc.,
• Table names
• name of entity
• prefix tables that are related ex: user_decisions, user_results
• no generic prefixes
• singular for table names
• columns
• use id for primary keys. user_id,
• foreign key should have id, cat_prod_id (refers to categories table, belongs to
products and is not a key)
• each column should be followed by a 3 letter table acronym. name_prd, name_cat
• Security
• SQL Injection - more here
SELECT fieldlist
FROM table
WHERE field = ‘'anything' OR 1=1’;

More Related Content

What's hot

Anchor Modeling ER09 Presentation
Anchor Modeling ER09 PresentationAnchor Modeling ER09 Presentation
Anchor Modeling ER09 PresentationRoenbaeck
 
An hour with Database and SQL
An hour with Database and SQLAn hour with Database and SQL
An hour with Database and SQLIraj Hedayati
 
XML Information set
XML Information setXML Information set
XML Information setHoang Nguyen
 
Presentation mc qs
Presentation mc qsPresentation mc qs
Presentation mc qsM Rafiq
 
Database design
Database designDatabase design
Database designRiteshkiit
 
Web Service Workshop - 3 days
Web Service Workshop - 3 daysWeb Service Workshop - 3 days
Web Service Workshop - 3 daysDavid Ionut
 
Core Data without headaches
Core Data without headachesCore Data without headaches
Core Data without headachesAbraham Barrera
 
Problem Solving with Algorithms and Data Structures
Problem Solving with Algorithms and Data StructuresProblem Solving with Algorithms and Data Structures
Problem Solving with Algorithms and Data StructuresYi-Lung Tsai
 
Searching for The Matrix in haystack (with Elasticsearch)
Searching for The Matrix in haystack  (with Elasticsearch)Searching for The Matrix in haystack  (with Elasticsearch)
Searching for The Matrix in haystack (with Elasticsearch)Tomas Sirny
 
Four Types of Data Models
Four Types of Data ModelsFour Types of Data Models
Four Types of Data ModelsDeanna Medina
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...Command Prompt., Inc
 
XML Schema Part 2
XML Schema Part 2XML Schema Part 2
XML Schema Part 2Dudy Ali
 

What's hot (20)

Anchor Modeling ER09 Presentation
Anchor Modeling ER09 PresentationAnchor Modeling ER09 Presentation
Anchor Modeling ER09 Presentation
 
An hour with Database and SQL
An hour with Database and SQLAn hour with Database and SQL
An hour with Database and SQL
 
Dom parser
Dom parserDom parser
Dom parser
 
XSL - XML STYLE SHEET
XSL - XML STYLE SHEETXSL - XML STYLE SHEET
XSL - XML STYLE SHEET
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
XML Information set
XML Information setXML Information set
XML Information set
 
Xml presentation
Xml presentationXml presentation
Xml presentation
 
Presentation mc qs
Presentation mc qsPresentation mc qs
Presentation mc qs
 
Xml p5 Lecture Notes
Xml p5 Lecture NotesXml p5 Lecture Notes
Xml p5 Lecture Notes
 
Database design
Database designDatabase design
Database design
 
Web Service Workshop - 3 days
Web Service Workshop - 3 daysWeb Service Workshop - 3 days
Web Service Workshop - 3 days
 
Core Data without headaches
Core Data without headachesCore Data without headaches
Core Data without headaches
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
 
Problem Solving with Algorithms and Data Structures
Problem Solving with Algorithms and Data StructuresProblem Solving with Algorithms and Data Structures
Problem Solving with Algorithms and Data Structures
 
Searching for The Matrix in haystack (with Elasticsearch)
Searching for The Matrix in haystack  (with Elasticsearch)Searching for The Matrix in haystack  (with Elasticsearch)
Searching for The Matrix in haystack (with Elasticsearch)
 
Four Types of Data Models
Four Types of Data ModelsFour Types of Data Models
Four Types of Data Models
 
Xml schema
Xml schemaXml schema
Xml schema
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
 
XML Schema Part 2
XML Schema Part 2XML Schema Part 2
XML Schema Part 2
 
data Structure
data Structuredata Structure
data Structure
 

Viewers also liked

Rich Internet Applications and Flex - 6
Rich Internet Applications and Flex - 6Rich Internet Applications and Flex - 6
Rich Internet Applications and Flex - 6Vijay Kalangi
 
Introduction to cloud computing
Introduction to cloud computingIntroduction to cloud computing
Introduction to cloud computingVijay Kalangi
 
Rich Internet Applications and Flex - 4
Rich Internet Applications and Flex - 4Rich Internet Applications and Flex - 4
Rich Internet Applications and Flex - 4Vijay Kalangi
 
Tecnología multimedia
Tecnología multimediaTecnología multimedia
Tecnología multimediaNicole Lopez
 
Rothco Paracord Catalog
Rothco Paracord CatalogRothco Paracord Catalog
Rothco Paracord CatalogRothco Sales
 
[Giornate dell'E-Commerce 2015] Carlotta Taroni e Instagram come opportunità ...
[Giornate dell'E-Commerce 2015] Carlotta Taroni e Instagram come opportunità ...[Giornate dell'E-Commerce 2015] Carlotta Taroni e Instagram come opportunità ...
[Giornate dell'E-Commerce 2015] Carlotta Taroni e Instagram come opportunità ...Confesercenti Ravenna
 
Audience feedback
Audience feedbackAudience feedback
Audience feedbacktrishamedia
 
Rothco 2015 New Product Collection
Rothco 2015 New Product CollectionRothco 2015 New Product Collection
Rothco 2015 New Product CollectionRothco Sales
 

Viewers also liked (14)

Rich Internet Applications and Flex - 6
Rich Internet Applications and Flex - 6Rich Internet Applications and Flex - 6
Rich Internet Applications and Flex - 6
 
Introduction to cloud computing
Introduction to cloud computingIntroduction to cloud computing
Introduction to cloud computing
 
Rich Internet Applications and Flex - 4
Rich Internet Applications and Flex - 4Rich Internet Applications and Flex - 4
Rich Internet Applications and Flex - 4
 
cuellar
cuellarcuellar
cuellar
 
Root and tuber by gyarko
Root and tuber by gyarkoRoot and tuber by gyarko
Root and tuber by gyarko
 
Toetsen
ToetsenToetsen
Toetsen
 
132302047(1)
132302047(1)132302047(1)
132302047(1)
 
TimberTech
TimberTechTimberTech
TimberTech
 
Tecnología multimedia
Tecnología multimediaTecnología multimedia
Tecnología multimedia
 
Rothco Paracord Catalog
Rothco Paracord CatalogRothco Paracord Catalog
Rothco Paracord Catalog
 
[Giornate dell'E-Commerce 2015] Carlotta Taroni e Instagram come opportunità ...
[Giornate dell'E-Commerce 2015] Carlotta Taroni e Instagram come opportunità ...[Giornate dell'E-Commerce 2015] Carlotta Taroni e Instagram come opportunità ...
[Giornate dell'E-Commerce 2015] Carlotta Taroni e Instagram come opportunità ...
 
Audience feedback
Audience feedbackAudience feedback
Audience feedback
 
DOMAIN NAME
DOMAIN NAMEDOMAIN NAME
DOMAIN NAME
 
Rothco 2015 New Product Collection
Rothco 2015 New Product CollectionRothco 2015 New Product Collection
Rothco 2015 New Product Collection
 

Similar to Introduction to DB design

SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperSQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperPolish SQL Server User Group
 
Session 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSession 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSwapnilSaurav7
 
Unit I Database concepts - RDBMS & ORACLE
Unit I  Database concepts - RDBMS & ORACLEUnit I  Database concepts - RDBMS & ORACLE
Unit I Database concepts - RDBMS & ORACLEDrkhanchanaR
 
•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdfjyothimuppasani1
 
Database Indexes
Database IndexesDatabase Indexes
Database IndexesSperasoft
 
Tech Jam 01 - Database Querying
Tech Jam 01 - Database QueryingTech Jam 01 - Database Querying
Tech Jam 01 - Database QueryingRodger Oates
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server DatabasesColdFusionConference
 
Test driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDBTest driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDBAndrew Siemer
 
BI Knowledge Sharing Session 2
BI Knowledge Sharing Session 2BI Knowledge Sharing Session 2
BI Knowledge Sharing Session 2Kelvin Chan
 
Presenting Data Effectively in XPages - ATLUG May 2013
Presenting Data Effectively in XPages - ATLUG May 2013Presenting Data Effectively in XPages - ATLUG May 2013
Presenting Data Effectively in XPages - ATLUG May 2013balassaitis
 
Schema less table & dynamic schema
Schema less table & dynamic schemaSchema less table & dynamic schema
Schema less table & dynamic schemaDavide Mauri
 

Similar to Introduction to DB design (20)

Java JDBC
Java JDBCJava JDBC
Java JDBC
 
Module 3 design and implementing tables
Module 3 design and implementing tablesModule 3 design and implementing tables
Module 3 design and implementing tables
 
Effective DB Interaction
Effective DB Interaction Effective DB Interaction
Effective DB Interaction
 
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperSQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
 
Session 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSession 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdf
 
Unit I Database concepts - RDBMS & ORACLE
Unit I  Database concepts - RDBMS & ORACLEUnit I  Database concepts - RDBMS & ORACLE
Unit I Database concepts - RDBMS & ORACLE
 
•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Database intro
Database introDatabase intro
Database intro
 
Database Indexes
Database IndexesDatabase Indexes
Database Indexes
 
Understanding indices
Understanding indicesUnderstanding indices
Understanding indices
 
MS ACCESS
MS ACCESSMS ACCESS
MS ACCESS
 
Tech Jam 01 - Database Querying
Tech Jam 01 - Database QueryingTech Jam 01 - Database Querying
Tech Jam 01 - Database Querying
 
SQL
SQLSQL
SQL
 
demo2.ppt
demo2.pptdemo2.ppt
demo2.ppt
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
Test driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDBTest driving Azure Search and DocumentDB
Test driving Azure Search and DocumentDB
 
BI Knowledge Sharing Session 2
BI Knowledge Sharing Session 2BI Knowledge Sharing Session 2
BI Knowledge Sharing Session 2
 
Presenting Data Effectively in XPages - ATLUG May 2013
Presenting Data Effectively in XPages - ATLUG May 2013Presenting Data Effectively in XPages - ATLUG May 2013
Presenting Data Effectively in XPages - ATLUG May 2013
 
Schema less table & dynamic schema
Schema less table & dynamic schemaSchema less table & dynamic schema
Schema less table & dynamic schema
 

Recently uploaded

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

Introduction to DB design

  • 2. • Plan your db • What information must be stored? • In which tables • In what form?
  • 3. • Goal of db design • Minimum redundancy • Integrity (Relational and data) • Performance
  • 4. • Normalization! • minimizes redundancy • no anomalies • update - same data in two places • delete - only one record • insert - inserting one attribute requires inserting additional info. • HTML and browser as a thin client • Page based architecture • Distribution problem solved!
  • 5. • Keys • unique • primary • foreign • composite • candidate
  • 6. • Relations • one-one • one-many • many-many
  • 7. • Joins • inner join - only when there is a match • left join - all from first table even if there are no matches in second table • right join - all from 2nd table even if there are no matches in first table • outer join - An OUTER JOIN retrieves data from both tables, when there are no matching values in the tables.The end result will be a summation of all rows in both tables.
  • 8. • Example SELECT * FROM product_prd INNER JOIN category_ctg ON product_prd.idctg_prd = category_ctg.id_ctg
  • 9. • Best practices • Comment • don’t store binary data • same column in diff. tables should have same datatype (ex: foreign key) • no select * • when running an insert action query, use the columns list into which to insert instead of the table name
  • 10. • Why naming convention • Clear structure • Everyone is on same page • Maintenance
  • 11. • use project name as the name of database
  • 12. • prefix the db name with the name of environment - proto_DB live_DB etc., • Table names • name of entity • prefix tables that are related ex: user_decisions, user_results • no generic prefixes • singular for table names
  • 13. • columns • use id for primary keys. user_id, • foreign key should have id, cat_prod_id (refers to categories table, belongs to products and is not a key) • each column should be followed by a 3 letter table acronym. name_prd, name_cat
  • 14. • Security • SQL Injection - more here SELECT fieldlist FROM table WHERE field = ‘'anything' OR 1=1’;