Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Year Based Primary Key?

How can I create a Primary Key in SQL Server 2005/2008 with the format: CurrentYear + auto-increment?

Example: The current year is 2010, in a new table, the ID should start in 1, so: 20101, 20102, 20103, 20104, 20105... and so on.

like image 368
brunosp86 Avatar asked Jul 15 '10 14:07

brunosp86


1 Answers

The cleaner solution is to create a composite primary key consisting of e.g. Year and Counter columns.

like image 142
Pontus Gagge Avatar answered Sep 24 '22 04:09

Pontus Gagge