I would recommend creating tbl_pics with an IDENTITY column as well. The query below should populate tbl_pics for you.
INSERT INTO tbl_pics (ProductID, ImageData)
SELECT ID, ImageData FROM tbl_Products
Main Topics
Browse All TopicsI have a table that currently supports 1 photo per product inserted. I have created this script and will attach it below. What I do not know how to do because I have never needed to do it is how to build a foreign key to another table which I need to create which will support multiple photos per item.
What I had in mind is to create a table, named tbl_pics which has a foreign unique key to ID. Could somebody show me how to do it? It is a simple procedure but I have never done it before.
Thanks for your help, all help is appreciated!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
It is standard database design....You use the 2nd table to store the pictures....it is a LOT easier to enter a record into a table rather than to add a field to a table each time a pic is added. It saves space, and time.
Here is a link on normalization (why its done).
http://en.wikipedia.org/wi
Ahhhhhh, you did not understand me I think!
I wanted another table to be created, with a first picture in tbl_products, and then the other pictures are in another table.
This is because what I had in mind, in my datagrid in ASP.NET, i make a navidational url, "View more pictures of this product" and then when i click that, i open a new window and do "select * from tbl_pics where picID=" & ID of selected row.
Does this make sense? Or do you think that I should put all images in one table?
Which approach are you refering to?
If you are refering to the addition of an IDENTITY column. Best practices dictate that you should always have a primary key. Other than the occasional lookup table I use an IDENTITY (or GUID if using replication) in every table. I have found through previous experience that the key value should be insignificant to the actual data. For example if you were creating a table of people it would be reasonable to use something like an SSN as the key but if for some reason you ever had to change the SSN you would have to cascade that value through all referencing tables . There are several other reasons that I won't go into such as join efficiency and the fact that it makes some queries much easier to write (remove duplicates) etal.
A hybrid of this if you want a primary photo but allow for multiples is to add a reference in the products table to the picture table. This would allow you the many-to-one relationship but still allow you to designate a primary image for display purposes. I've done this before with the primary address for a contact.
ALTER TABLE [dbo].[tbl_products]
ADD COLUMN PrimaryPic int NULL tbl_Pics(PicID)
Business Accounts
Answer for Membership
by: chapmandewPosted on 2008-03-07 at 14:50:49ID: 21074791
Sure...here is how you do it....I took you image column out of your first column and added it to the 2nd...you can keep it in the first table if you want...it won't hurt anything.....
The REFERENCES part of the 2nd table (new table) creates your foreign key constraint.
HTH,
Tim
Select allOpen in new window