Hi,
I have what I hope is a fairly simple question.
I have a database (SQL Server 2008 R2) that I'm designing from scratch. It's in the beginning coding phase, and this particular table doesn't have any code based on it yet, so I'm pretty flexible with changing things.
This database will potentially have several companies using it, all using the same tables, but black-boxed with procedures and insulated from each other (with the exception of a very few things, nothing any company enters should be able to affect any other company in any visible way). Each company has clients, who send the company jobs. Each company will be inputting their own data.
These jobs come in from various clients by the thousands. Each gets input into the system, and given the following "keys":
[ul=1]
[li]DatabaseJobID - PK of the Jobs table. Just your standard auto-increment. Used entirely behind the scenes, for internal searches and FK contstraints. Not clearly visible to humans.
[/li][li]CompanyJobRefNumber - Reference number used by the company to refer to the job. This consists of the year entered in one of the date fields (we'll call it StartDate), followed by a dash, followed by an incrementing number (displayed with leading 0's) which starts back at 1 each year. Needs to be unique, for that company and for that year. Not really negotiable - this is how the companies want it.
[/li][li]ClientJobRefNum (optional) - Reference "number" (I say number, but it really could be anything) optionally given to the company by the client. The company has no say in this number, but searches do need to be performable on this column.
[/li][/ul]
How to store the data and implement the logic is still pretty flexible at this point, but the behavior that's needed is pretty set in stone.
My question is: regarding #2 above... what is the most efficient way of doing this? The "auto-increment" portion needs to auto-increment within that company, and within that year. It should start each year back at 1, it can't have duplicates (within the same company and year), and it shouldn't skip numbers because of other companies.
Many thanks!
Katie
I have what I hope is a fairly simple question.
I have a database (SQL Server 2008 R2) that I'm designing from scratch. It's in the beginning coding phase, and this particular table doesn't have any code based on it yet, so I'm pretty flexible with changing things.
This database will potentially have several companies using it, all using the same tables, but black-boxed with procedures and insulated from each other (with the exception of a very few things, nothing any company enters should be able to affect any other company in any visible way). Each company has clients, who send the company jobs. Each company will be inputting their own data.
These jobs come in from various clients by the thousands. Each gets input into the system, and given the following "keys":
[ul=1]
[li]DatabaseJobID - PK of the Jobs table. Just your standard auto-increment. Used entirely behind the scenes, for internal searches and FK contstraints. Not clearly visible to humans.
[/li][li]CompanyJobRefNumber - Reference number used by the company to refer to the job. This consists of the year entered in one of the date fields (we'll call it StartDate), followed by a dash, followed by an incrementing number (displayed with leading 0's) which starts back at 1 each year. Needs to be unique, for that company and for that year. Not really negotiable - this is how the companies want it.
[/li][li]ClientJobRefNum (optional) - Reference "number" (I say number, but it really could be anything) optionally given to the company by the client. The company has no say in this number, but searches do need to be performable on this column.
[/li][/ul]
How to store the data and implement the logic is still pretty flexible at this point, but the behavior that's needed is pretty set in stone.
My question is: regarding #2 above... what is the most efficient way of doing this? The "auto-increment" portion needs to auto-increment within that company, and within that year. It should start each year back at 1, it can't have duplicates (within the same company and year), and it shouldn't skip numbers because of other companies.
Many thanks!
Katie