Question

I'm currently working on a SQL assignment that wants me to: Add an index for each foreign key and an index on Company for Customer and Shipper.

I've created the 3 tables that were needed, created the foreign and primary keys, and so on. But my textbook has not mentioned anything about indices and I am at a loss as to what to do. If you have an answer, it'd be nice to know how you got to it.

The structure of the tables:

Customer

CustomerID (PK) | Company   | ContactName  | Phone

Order

OrderID (PK)    | OrderDate | ShippedDate  | ShipperID  | Freight  | CustomerID (FK)

Shipper

ShipperID (PK)  | Company   | Phone
Was it helpful?

Solution

You should be looking at the online documentation, but...

To create indexes for foreign keys:

create index Order_ShipperID on Order(ShipperID);
create index Order_CustomerID on Order(CustomerID);

To create indexes on Company for Customer and Shipper:

create index Customer_Company on Customer(Company);
create index Shipper_Company on Shipper(Company);

The names of the indexes can be anything, but I usually follow this naming convention.


BTW, the choice of name "Order" is a poor one because its a reserved word.

OTHER TIPS

You can create Index on any SQL Table column. Once Indexes are created on your Table column you just have to send the Select query and you can check logically the performance of you query. You can check the next link for reference to the solution:

www.blog.mastersoftwaresolutions.com/how-do-database-indexes-work/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top