MySQL: FOREIGN KEYS are easy (kind of)

MySQL: FOREIGN KEYS are easy (kind of)

Bro Code

1 год назад

184,331 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Bro Code
Bro Code - 27.10.2022 04:38

CREATE TABLE customers (
customer_id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(50),
last_name VARCHAR(50)
);
INSERT INTO customers (first_name, last_name)
VALUES ("Fred", "Fish"),
("Larry", "Lobster"),
("Bubble", "Bass");
SELECT * FROM customers;

-- Add a named foreign key constraint to a new table
CREATE TABLE transactions (
transaction_id INT PRIMARY KEY AUTO_INCREMENT,
amount DECIMAL(5, 2),
customer_id INT,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
ALTER TABLE transactions
AUTO_INCREMENT = 1000;

-- Add a named foreign key constraint to an existing table
ALTER TABLE customers
ADD CONSTRAINT fk_customer_id
FOREIGN KEY (customer_id) REFERENCES customers(customer_id);

Ответить
babajide amure
babajide amure - 26.09.2023 16:42

@brocode I am late to the party. This is hands down the best video I have watched to explain PK and FK. Thank you

Ответить
Sami Tee
Sami Tee - 13.09.2023 23:51

The typing sound is so satisfying😅

Ответить
inday sa balitaw
inday sa balitaw - 08.08.2023 02:35

i like ur videos short and unique style of teaching, very easy to get, specially my main language is not english

Ответить
Mathew G Kuzhivelil
Mathew G Kuzhivelil - 05.08.2023 16:07

What if I have 3 tables and the 2 nd table has a dk with 3 rd table and vice-versa and it shows error while execution.

Ответить
Debajit Sil
Debajit Sil - 17.07.2023 00:03

Thanks a ton Man!

Ответить
LUCKY CREATIVE
LUCKY CREATIVE - 03.07.2023 20:50

I HAVE A QUESTION WHY YOU HAVE DROPPED THE TABLE?
PLS CAN SOMEONE RESPOND!!!!

Ответить
Fahrie Kurniadi
Fahrie Kurniadi - 20.06.2023 10:38

thank you so much, help me to understand

Ответить
Xeloz Zen
Xeloz Zen - 03.06.2023 16:58

why is mine key.. doesn't exist in table i write it exact like yours tho

Ответить
Muhammad Amrin Lubis
Muhammad Amrin Lubis - 16.05.2023 05:43

nice video, easy to understand. May Allah increase your knowledge and be blessed with knowledge

Ответить
MissMaria Tv
MissMaria Tv - 19.04.2023 17:33

bro why u always have the BEST tutorials out there and as much as i search the whole yt i always end up warching YOUR vids?😂 keep up the good work man all of us IT students appreciate it. you are far better than our professors

Ответить
Vishal Mane
Vishal Mane - 18.04.2023 09:09

didnt work..column missing

Ответить
Mr. Clean
Mr. Clean - 15.04.2023 09:27

Thank you so much!!!

Ответить
Mukhtar Abebefe
Mukhtar Abebefe - 10.04.2023 16:08

Thank you

Ответить
Mithun Chandra Saha
Mithun Chandra Saha - 28.03.2023 14:33

Very Nice Explanation,Sir.Needs More.

Ответить
FG BEAST
FG BEAST - 28.03.2023 08:44

You are the best! You make a difference on this world!

Ответить
SQUIDY GAMES
SQUIDY GAMES - 19.02.2023 10:47

Bro your tutorials are better than my sql teacher , you probly saved my test and also made me appreciate sql way more, much thanks!

Ответить
boogieman
boogieman - 11.02.2023 16:34

What is transaction_ibfk_1?

Ответить
boogieman
boogieman - 10.02.2023 21:34

Can we put a foreign key in a constraint. Like table_1 has column_D.O.B as primary key and table_2 has column_joining_date and joining_date should be greater than D.O.B .

How do we do that?

Ответить
BartsWorkshop
BartsWorkshop - 07.02.2023 11:18

Thank you, you made this super easy to understand! One question, would the foreign key ever be a primary key as well in the transactions table?

Ответить
Aatif Mohammed
Aatif Mohammed - 14.01.2023 04:50

how to make foreign key on non primary columns?

Ответить
pdalmao
pdalmao - 03.12.2022 00:03

This has saved my life! Managed to get my module done with weeks to spare thanks to you :)

Ответить
Maaboii
Maaboii - 28.10.2022 18:41

Really frustrated till now trying to learn how primary key work.
I have no idea how to insert multiple same column data (the assigment the gave me) meanwhile primary key doesn't work if you add duplicate data, besides that problem i pretty much know well how to use mySQL, thanks to this video ofc

Ответить
Bexa Code
Bexa Code - 28.10.2022 16:07

I really like all your videos!
And I really want you will upload about Spring Framework. 😇

Ответить
Lykkos
Lykkos - 27.10.2022 22:34

very concise and understandable, thanks master!

Ответить
Change-Yourself
Change-Yourself - 27.10.2022 18:17

Hey Bro Code, Can you please please help me with creating a draw method in a tick-tak-toe game you created your-self, I really want that, and I've been trying for weeks, but I could not figure any way out. Please if you know how to create one, replay in my comment.

Ответить
Tom H
Tom H - 27.10.2022 18:01

Great video! Any plans on covering relational databasing? That's probably the next thing that stumps a lot of people imo
Also huge respect for the fundraiser, it's a great cause :)

Ответить
Romuald Sibakovskij
Romuald Sibakovskij - 27.10.2022 17:49

Cool video bro :) better than going through theoretical crap - straight to action

Ответить
TheLastRaven
TheLastRaven - 27.10.2022 17:07

Litarly covered this in class yesterday tnx Bro! Your timing is as always great

Ответить
red_uwu
red_uwu - 27.10.2022 17:04

Weeks of classes condensed into just a few videos, thank you for making this!

Ответить
Bekir S
Bekir S - 27.10.2022 17:02

I rarely need these kinds of videos but i still click and give a like just cuz ur a good guy and teacher

Ответить