Premium Only Content
			Java Spring Boot [Mid 2024] Part 9: Relational Mappings
*******************OneToOne*******************
CREATE TABLE address (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
street VARCHAR(255),
city VARCHAR(255),
state VARCHAR(255)
);
CREATE TABLE customer (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(255),
last_name VARCHAR(255),
address_id BIGINT,
FOREIGN KEY (address_id) REFERENCES address(id)
);
INSERT INTO address (street, city, state) VALUES ('123 Main St', 'Cityville', 'CA');
INSERT INTO customer (first_name, last_name, address_id) VALUES ('John', 'Doe', 1);
*******************OneToMany*******************
ALTER TABLE address
ADD COLUMN customer_id BIGINT,
ADD CONSTRAINT fk_customer
FOREIGN KEY (customer_id)
REFERENCES customer (id);
UPDATE address
SET customer_id = (SELECT id FROM customer WHERE id = address.id);
INSERT INTO customer (first_name, last_name) VALUES ('Jane', 'Smith');
INSERT INTO address (street, city, state, customer_id) VALUES
('789 Pine St', 'CityC', 'SC', 1),
('101 Elm St', 'CityD', 'SC', 2);
ALTER TABLE customer
DROP FOREIGN KEY customer_ibfk_1;
ALTER TABLE customer
DROP COLUMN address_id;
******************ManytoMany*******************
CREATE TABLE customer_address (
customer_id BIGINT,
address_id BIGINT,
PRIMARY KEY (customer_id, address_id),
FOREIGN KEY (customer_id) REFERENCES customer(id),
FOREIGN KEY (address_id) REFERENCES address(id)
);
INSERT INTO customer_address (customer_id, address_id)
SELECT customer_id, id as address_id
FROM address;
ALTER TABLE address
DROP FOREIGN KEY fk_customer;
ALTER TABLE address
DROP COLUMN customer_id;
- 	
				
							21:39
								Nikko Ortiz
2 days agoI Take A North Korean Shooting
14.3K5 - 	
				
							1:46:26
								The Michelle Moore Show
18 hours ago'The Religion Invasion In the U.S. and the Deep State Agenda' Guest, Mark Taylor: The Michelle Moore Show (Nov 3, 2025)
21.3K26 - 	
				
							LIVE
								TruthStream with Joe and Scott
5 days agoSovereign Codes & Cosmic Infrastructure,Ufo's, UAP's, Monads, Matrix Satellites, Interstellar Visitors, SYRONA #505
346 watching - 	
				
							LIVE
								Lofi Girl
2 years agoSynthwave Radio 🌌 - beats to chill/game to
165 watching - 	
				
							5:55:11
								MattMorseTV
11 hours ago $93.78 earned🔴Trump's '60 Minutes' INTERVIEW + MUCH MORE.🔴
157K48 - 	
				
							2:02:36
								Badlands Media
16 hours agoBaseless Conspiracies Ep. 157: Jack the Ripper, the Crash & the Great Disclosure Countdown
35.6K22 - 	
				
							2:06:09
								Inverted World Live
12 hours agoMysterious Crash at Area 51 | Ep. 134
40K15 - 	
				
							2:48:59
								TimcastIRL
10 hours agoTrump Endorses Cuomo, Says NO COMMIE MAMDANI, Obama REFUSES To Endorse Mamdani | Timcast IRL
276K210 - 	
				
							5:51:16
								Drew Hernandez
1 day agoGOP CIVIL WAR: TUCKER CARLSON DERANGEMENT SYNDROME AT ALL TIME HIGH
57.2K42 - 	
				
							14:44
								Sponsored By Jesus Podcast
1 day agoYou Can't Serve God & MONEY | Is Money the Root of All Evil?
26K25