troubleshooting Question

Composite Key With "Dynamic" Identity Column or Something Similar

Avatar of dwechter
dwechter asked on
Microsoft SQL Server 2005SQL
5 Comments2 Solutions706 ViewsLast Modified:
Hi All -

Relatively simple idea here, but one that has me a bit stumped as to the best solution.  I want to create an MS SQL table that will store comments related to account issues.  I want to identify, in a composite key, the account number and the incremental comment number (1, 2, 3).  When a new account number is added, again I want to identify that comment number incrementally.  A composite of ACCT_NUM (integer) and COMMENT_NUM (identity integer) works for the first account, but the identity number will continue upward indefinitely and will not properly reset to number the comment by account.

So, experts, any ideas to create the following?  The preference would be that it happens at the table level, and not in an insert command (if possible)!

987654           1
987654           2
456123           1
456123           2
456123           3
222222           1
333333           1

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 5 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 2 Answers and 5 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