Complete the code to create a foreign key linking the orders table to the customers table.
ALTER TABLE orders ADD CONSTRAINT fk_customer_id FOREIGN KEY ([1]) REFERENCES customers(id);id of the orders table instead of the foreign key column.The foreign key column in the orders table that links to the customers table is customer_id. This column must match the primary key id in customers.
Complete the code to select all orders with customer names by joining orders and customers using the foreign key.
SELECT orders.id, customers.name FROM orders JOIN customers ON orders.[1] = customers.id;orders.id = customers.id.orders.The join condition uses the foreign key customer_id in orders to match the primary key id in customers.
Fix the error in the foreign key constraint by completing the code correctly.
ALTER TABLE orders ADD CONSTRAINT fk_customer FOREIGN KEY ([1]) REFERENCES customers([2]);
customers.orders.The foreign key column in orders is customer_id and it references the primary key id in customers.
Fill both blanks to create a table payments with a foreign key linking to orders.
CREATE TABLE payments (id INT PRIMARY KEY, order_id INT, FOREIGN KEY ([1]) REFERENCES orders([2]));
orders.The foreign key column in payments is order_id which references the primary key id in orders.
Fill all three blanks to select payment ids and customer names by joining payments, orders, and customers using foreign keys.
SELECT payments.id, customers.name FROM payments JOIN orders ON payments.[1] = orders.[2] JOIN customers ON orders.[3] = customers.id;
payments.id or orders.customer_id incorrectly.The joins use the foreign key order_id in payments matching id in orders, and customer_id in orders matching id in customers.