Create a table with two foreign keys?

I have a question on how to set up this relationship in my database

I have racks which can hold man devices.
Each device is connected to its own power supply.
So, it looks like ill need 3 tables:

CREATE TABLE power_supply (
power_supply_id INT AUTO_INCREMENT PRIMARY KEY,
...
...
)
CREATE TABLE rack (
rack_id INT AUTO_INCREMENT PRIMARY KEY,
...
...
)
//I guess I want to link each device to a rack & power supply?
//can I have 2 foreign keys like
CREATE TABLE device (
device_id INT AUTO_INCREMENT PRIMARY KEY,
rack_id INT,
power_supply_id INT,
...
...
FOREIGN KEY (rack_id) REFERENCES rack (rack_id),
FOREIGN KEY (power_supply_id) REFERENCES power_supply (power_supply_id)
)

what happened when you tested it? ™

4 Likes

oh, it works, had a typo