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);
@ahmedhussein6359
Жыл бұрын
two typo errors: -- Add a named foreign key constraint to a new table //TYPO ERROR 1: should be unnamed 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 //TYPO ERROR 2: should be transactions ADD CONSTRAINT fk_customer_id FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
@red_uwu
Жыл бұрын
Weeks of classes condensed into just a few videos, thank you for making this!
@maraki_zrg
Жыл бұрын
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
@vishalplayzz2580
Жыл бұрын
true
@FunTubexArabic
4 ай бұрын
True I share that point I even learned English to understand Him 😂😂 if I stay At home watching his videos I see much better than going to school wasting time and make my life miserable
@pdalmao
Жыл бұрын
This has saved my life! Managed to get my module done with weeks to spare thanks to you :)
@TheLastRaven
Жыл бұрын
Litarly covered this in class yesterday tnx Bro! Your timing is as always great
@ArielLegoAndMore
Жыл бұрын
Bro your tutorials are better than my sql teacher , you probly saved my test and also made me appreciate sql way more, much thanks!
@FunTubexArabic
4 ай бұрын
The point is that he Took A serious lesson to funny story So hilarious 😂😂
@markvilla7796
Жыл бұрын
I am not IT student. I am lucky I found your channel :)
@mehmetoz886
8 ай бұрын
I am preparing for an interview. The explanation was simple and included good examples.
@fgbeast5805
Жыл бұрын
You are the best! You make a difference on this world!
@sominramchiary5880
3 ай бұрын
unique key is easy, auto_increment is awesome and foreign_keys are easy (kind of), HUh!! Bro made it easy.
@bekirs4240
Жыл бұрын
I rarely need these kinds of videos but i still click and give a like just cuz ur a good guy and teacher
@loebys
Жыл бұрын
nice video, easy to understand. May Allah increase your knowledge and be blessed with knowledge
@amroulouay6819
Жыл бұрын
👍
@bartsworkshop
Жыл бұрын
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?
@babajideamure108
Жыл бұрын
@brocode I am late to the party. This is hands down the best video I have watched to explain PK and FK. Thank you
@celestepozzi9204
Жыл бұрын
i like ur videos short and unique style of teaching, very easy to get, specially my main language is not english
@maaboii5431
Жыл бұрын
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
@gopinath9986
3 ай бұрын
so clean and neet and explained perfectly
@drawdownfx4415
5 ай бұрын
this is great thanks. To do joins between two tables do we need to specifiy primary and foreign keys? What if you have two tables with no constraints? would it still be possible to do join queries
@mithunchandrasaha403
Жыл бұрын
Very Nice Explanation,Sir.Needs More.
@wolfdogfifa
29 күн бұрын
Is there a way to display the first name of the customer in the transactions table by using the customer_id as the foreign key? Or would you have to make the first name the foreign key to display it in the table?
@sandyiwadeakhia4435
2 ай бұрын
Please,I need video on how to create multiple tables on postgreSQL.....
@jubibi390
11 ай бұрын
This saved me. I love you Bro.
@tomh6010
Жыл бұрын
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 :)
@meitangyoon7087
Жыл бұрын
Great lessons - as a beginner, it's short & sweet makes it easy to follow & understand. Seen other youtube lessons - difficult to follow for beginners. The comments pinned by you are very helful guide & notes. Great job, kudos to you and look forward for more.
@fahriekurniadi403
Жыл бұрын
thank you so much, help me to understand
@bexacode1150
Жыл бұрын
I really like all your videos! And I really want you will upload about Spring Framework. 😇
@SchSlendy
3 ай бұрын
"im going to delete some of our customers" made me laugh xd. this tutorial is very cool, good work bro!
@boogieman8827
Жыл бұрын
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?
@samitee8336
Жыл бұрын
The typing sound is so satisfying😅
@Lifeofrandomness
Жыл бұрын
Thanks a ton Man!
@mr_clean575
Жыл бұрын
Thank you so much!!!
@lorenne928
Жыл бұрын
very great
@mukhtarabebefe7596
Жыл бұрын
Thank you
@NerdyGeecks
4 ай бұрын
hello, can someone explain on how to insert an existing foreign key into two tables like inserting user_id and two tables like transaction and reserve in phpmyadmin?
@ToughNevyHacSoc
Жыл бұрын
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.
@mohaymenul-islam
6 күн бұрын
✅
@korosai
7 ай бұрын
why you use transaction_id as a primary key if we don’t pair it with a foreign key?
@luckycreative7418
Жыл бұрын
I HAVE A QUESTION WHY YOU HAVE DROPPED THE TABLE? PLS CAN SOMEONE RESPOND!!!!
@freezeyourmind7011
Жыл бұрын
I don't understand it too, he deleted table but still can link and use it
@luffy_viz
4 ай бұрын
I see last that line delete form table name and where name = ' vishwa ' ; but I can't delete then how to delete in 2 tables
@MathewGKuzhivelil
Жыл бұрын
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.
@suryatejamukka5564
2 ай бұрын
Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint 'idx_product_name' in the referenced table 'products' What is this how to solve this
@aatifmohammed7031
Жыл бұрын
how to make foreign key on non primary columns?
@maxxcleiton
4 ай бұрын
FOREIGN KEY is a PRIMARY KEY from another table. The definition by itself answers your question.
@sandyiwadeakhia4435
2 ай бұрын
How do i create two foreign keys in a table?
@evanlin7656
2 ай бұрын
i like Bubble bass
@ambi297
5 ай бұрын
in my sql the data is not taking it says cannot foreign key constraints unable to different tyoes alo what shell i do????
@aetyrunner
4 ай бұрын
Pk and FK must have same data type, like INT/SMALLINT/etc are all INT, but not like INT-DECIMAL or INT-VARCHAR Then if your PK is SMALLINT (one of most common cases I guess) your FK should be: column_id INT, FOREING KEY(column_id) REFERENCES table(column_id)
@enriquepasa
Жыл бұрын
Cool video bro :) better than going through theoretical crap - straight to action
@xelozzen5312
Жыл бұрын
why is mine key.. doesn't exist in table i write it exact like yours tho
@amroulouay6819
Жыл бұрын
Why the unique name should be fk 😂😂4:17
@vishalmane3139
Жыл бұрын
didnt work..column missing
@f15srinivas82
5 ай бұрын
i didnt see god . even i didnt see you bro
@dlamontw
6 ай бұрын
nice ok. i think i got it
@AZZAMNO1
9 ай бұрын
maybe this will be useful for someone in future i'll drop this here. ALTER TABLE student ADD COLUMN student_loginUsername VARCHAR(35), ADD FOREIGN KEY (student_loginUsername) REFERENCES login(login_username);
Пікірлер