How Add a Foreign Key Constraint (Make Relationships) in MySQL WorkBench

  Рет қаралды 139,496

Matt Macarty

Matt Macarty

Күн бұрын

‪@MattMacarty‬
#mysql #workbench #foreignkey
✅ Please SUBSCRIBE:
kzbin.info_...
Add and work with foreign key constraints in MySQL
✅ Pure SQL Tutorial starts 7:18
✅ How to Create Databases:
• How to Create a Databa...
✅ How to Create EER Diagrams:
• How to Make and Use an...
✅ Link to GitHub:
github.com/mjmacarty/mysql
In this video I am going to demonstrate add a foreign key contraint in MySQL and create relationships using the workbench. See the link to download the two tables used from GitHub so you can follow along. The tables customers and orders, so we can imagine the relationships there where one customer places many orders (hopefully).
We start off by examining and ERD of the unrelated tables. We can use the EER diagram to manually add the one-to-many relationship button here and draw the relationship in between the tables, however for this to take effect you would need to forward engineer the diagram into a new database.
There are a number of different ways we add foreign key constraints, and the video covers the methods to do this in the workbench. First I'm going to use the GUI method, and then we will see how to do the same thing with pure SQL. The requirements are the same regardless of which method you use: you need to relate a primary key from one table to a column in a second table of the same data type and size. A couple of things to keep in mind, 1. when you import data MySQL tends to make it as generic as possible. For example any string data will be imported as text datatype; 2. MySQL does not allow text data to be defined as a primary key. MySQL allows CHAR data and INT data to be defined as primary keys. For speed, INT data is preferred, but we will be using CHAR data in this video.
Some people prefer the GUI interaction since you can simply point click and drag. In reality, though the Workbench generates all the required SQL, which you have "apply". To me it's not easier to use the GUI interface, and I prefer the PURE SQL method. In addition, since we are dealing with SQL there's always or usually more than one way of doing things. I am going to ALTER the tables using the MODIFY keyword on the columns of interest to add both primary and foreign keys.

Пікірлер: 68
MySQL PRIMARY KEY & FOREIGN KEY Tutorial in Hindi / Urdu
14:56
Yahoo Baba
Рет қаралды 327 М.
Primary & Foreign Keys
8:25
Eddie Woo
Рет қаралды 473 М.
Inside Out 2: Who is the strongest? Joy vs Envy vs Anger #shorts #animation
00:22
Double Stacked Pizza @Lionfield @ChefRush
00:33
albert_cancook
Рет қаралды 86 МЛН
39kgのガリガリが踊る絵文字ダンス/39kg boney emoji dance#dance #ダンス #にんげんっていいな
00:16
💀Skeleton Ninja🥷【にんげんっていいなチャンネル】
Рет қаралды 8 МЛН
Installing MySQL and Creating Databases | MySQL for Beginners
12:04
Alex The Analyst
Рет қаралды 338 М.
Relational vs. Non-Relational Databases
8:12
IBM Technology
Рет қаралды 102 М.
MySQL: FOREIGN KEYS are easy (kind of)
8:17
Bro Code
Рет қаралды 200 М.
Learning MySQL - FOREIGN KEY CONSTRAINTS
11:52
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 44 М.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 185 М.
Learn SQL In 60 Minutes
56:24
Web Dev Simplified
Рет қаралды 2,1 МЛН
SQL Tutorial for Beginners [Full Course]
3:10:19
Programming with Mosh
Рет қаралды 11 МЛН
How I use SQL as a Data Analyst
15:30
Luke Barousse
Рет қаралды 814 М.