troubleshooting Question

Inserting records into an MSSQL table with combined primary key

Avatar of ncw
ncw asked on
Microsoft SQL ServerMicrosoft SQL Server 2005
10 Comments1 Solution850 ViewsLast Modified:
If I have 3 tables eg products, products_to_categories, and categories. If I insert a record into table products then I also want to insert a corresponding record into products_to_categories, and categories. Each of these talbes has a primary key, products.product_id, categories.category_id, then for products_to_categories there's a combined key (or clustered it might be called) that is product_id and category_id, this table being used to link products to categories. (I'm converting an existing MySql Db)

Now If I insert a record into categories then I think I can probably set the categorie_id value if the column has an IDENTITY (is that right), but how do I set the values of the 2 id fields in products_to_categories?  (I'm an MSSQL beginner)
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros