squirrelworks

Foreign key constraint demo



The goal is to create a dropdown selection in the 'navbar' table for navbar category, linked to it's own 'navbar category' table

Let's examine the steps for setting this up.

The final result will look like this.
Inserting a new row in 'Navbar':




'Navbar' > Structure - showing the foreign key in row 2, and at the bottom under 'indexes'.





To add the constraint:
Structure > Relation View





Browsing the 'Navbar' table. The foreign key in column 2.



This means we're only holding that value in this table; the unique id of a row in a different table, 'navbarcategories'. The details of that row arent important here. We just need a hook.

That hook allows the PHPAdmin UI that we're working in to give more detail about which row its referring to, in this case, the name of the navbar category that the row id is linked to.



Within PHPMyAdmin as shown here, the UI does some extra querying in order to show us the id# and the name of the category, resulting in meaninful data displayed to us upon which we can act. Later in PHP we can similarly query various tables this way, to build a complete record of something.

Again- the only value from the 'navbarcategory' table that we keep track of in the 'navbar' table is the idNavCategory. We then take that key over to it's origina table for more info. That is the idea here.

Foreign key = another table's primary key.





The constraint comes in when we disallow deletion or changes. Those actions can break the whole logic of an app. The default is 'restrict'.



and there are additional options:



To show this in action I'll attempt to delete for id#26 from the navbar categories table.



The constraint stops the action to protect the db integrity.









Accessibility
 --overview

Agile
 --DevOps overview
 --Principles

API
 --REST best practices
 --REST demo
 --REST vs RPC
 --Wikipedia API

Blockchain
 --overview

Cloud
 --AWS overview

CSS/HTML
 --Bootstrap carousel
 --Grid demo
 --markdown demo

Electricity
 --fundamentals

Encoding
 --Overview

Ergonomics
 --Desk configuration
 --Device fleet
 --Input device array
 --keystroke mechanics
 --Phones & RSI

ERP
 --Anthology overview
 --Ellucian Banner
 --Higher Ed ERP Simulation Lab
 --PeopleSoft Campus Solutions
 --PESC standards
 --Slate data model

Git
 --syntax overview
 --troubleshooting libcrypto

Hardware
 --Device fleet
 --Homelab diagram

Java
 --Fundamentals

Javascript
 --Advanced Interaction: jQuery & UI Frameworks
 --input prompt demo
 --misc demo
 --Time and Date functions
 --Vue demo

Linux
 --grep demo
 --HCI and Proxmox
 --Proxmox install
 --xammp ftp server

Mail flow
 --DKIM, SPF, DMARC
 --MAPI

Microsoft
 --AZ-800: Administering Windows Server Hybrid Core Infrastructure
 --BAT scripting
 --Group Policy
 --IIS
 --robocopy
 --Server 2022 setup - Virtualbox

Misc
 --Applications
 --regex
 --Resources
 --Sustainable Computing
 --Terminology
 --Tribute to Computer Scientists

Networks
 --BGP Peering & Security Hardening Lab
 --CCNA Lammle Study Guide
 --Cisco 1921/K9 router
 --routing protocols
 --throughput calculations

PHP/SQL
 --Cookies
 --database interaction
 --demo, OSI Layers quiz
 --Foreign key constraint demo
 --fundamentals
 --MySQL and PHPmyAdmin setup
 --pagination
 --security
 --session variables
 --SQL fundamentals
 --structures
 --Tables display

Python
 --fundamentals

Security
 --Overview- GRC (Governance, Risk, and Compliance)
 --Security Blog
 --SSH fundamentals

Serialization
 --JSON demo
 --YAML demo