sql / intermediate
Snippet
Indexing Foreign Key Columns for Faster Joins
Creating non-clustered indexes on foreign key columns speeds up relational joins and foreign key validation checks. Database engines use these indexes to avoid full table scans when parent-child records are linked in queries.
snippet.sql
sql
1
2
CREATE INDEX idx_orders_customer_idON orders (customer_id);
Breakdown
1
CREATE INDEX idx_orders_customer_id
Declares the creation of a new database index named idx_orders_customer_id.
2
ON orders (customer_id);
Specifies the target table ('orders') and column ('customer_id') to be indexed.