I have a set of two tables which store information about products. I support versioning in my database, which means that I track changes made to product descriptions.
I decided that at a fundamental level, there were two sets of characteristics which belong to a product: those that are time-less, and those bound by time.
ProductID would be time-less.
Name and description would be time-bound.
So I set up two tables:
tblProduct
- productID int IDENTITY
tblProductVersion
- productID int REFERENCES tblProduct
- timestamp
- name varchar(255)
- description text
I wrap all my data access in stored procedures. So I created an SP for adding a new product, which entails:
1. Inserting a row into tblProduct, then getting the @@IDENTITY value.
2. Inserting a row into tblProductVersion with the productID and other characteristics.
So that's why I have a table with only one field. No, I do not want to write my own scheme for assigning productIDs. That's why I chose to use IDENTITY columns. Please don't post any messages telling me my way is wrong.
Does anyone know how to do this insert?