I can definately improve on that. As a general rule, if you have to reserve lots of empty columns for an indefinate number of values or modify a table to add columns ad hoc to store an indefinate number of values, then that data should be stored in a separate table. I think of it as storing the data vertically rather than horizontally.
Here's what I would do:
Keep "customers" as it is.
Keep "downloads" as it is when you first create it. Keep only the ID, filename, description, filetype columns.
Then create a third relating table. It will have two columns: one for the unique customer ID, another for the unique file ID. An entry in this table will relate a customer to a file. Multiple files can be related to multiple customers -- just add records to this table as necessary to record the relation.
In case I'm not clear, please let me show an explicit example. Assume you have three customers and three files. Customer1 has access only to FileA, Customer2 has acess to FileB and FileC, and Customer3 has access only to FileC.
"Customers" would look something like:
Code:
CustomerID CustomerName ...
1 Adam's Ales ...
2 Bill's Beers ...
3 Chuck's Cognacs ...
"files" would look something like:
Code:
FileId Filename Filedescription ...
1 aims.txt a contract spec ...
2 beasts.gif an image ...
3 coopers.pdf an Acrobat doc ...
Then the "customers2files" relating table would look something like:
Code:
Customer File
1 1
2 2
2 3
3 3
Then to fetch all the files accessible by a single customer, perform a select query of the form:
SELECT *
FROM customers c, customers2files c2f, files f
WHERE c.CustomerID = c2f.Customer and
c2f.File = f.FileID and
c.CustomerID = <customer's ID>
Want the best answers? Ask the best questions: TANSTAAFL!!