SQL Simple -> Create Indexed Table

Suppose that we want to create indexed list of Customers that purchased something in the past (Customers that exists in Invoice records). This is a simple task. Lets see the syntax.

-- save grouped data into new table Invoice_Customers

SELECT CustomerID, CustomerName INTO Invoice_Customers
FROM Invoice
GROUP BY CustomerID, CustomerName
ORDER BY CustomerID, CustomerName;


The table Invoice_Customers will look like this:
CustomerIDCustomerName
1Angelina Alba
2Jessica Simpson
3Barbara Spears
4Pestiana Oliviera
....

Create index:
-- create index on CustomerID column

CREATE UNIQUE INDEX index1_CustomerID
ON Invoice_Customers (CustomerID);


If you will want to remove index - the command is:
-- drop index

DROP INDEX index1_CustomerID ON Invoice_Customers;



sqlexamples.info