I have a table in SQL Server 2005 which contains some changelog data for a number of projects. These are stored in one table as there are hundreds of projects and the projectlog table can be queried for things like activity per day or per person.
Eg
projectlogidentity int identity
projectname nvarchar(100)
projectchanged datetime
projectchangedby nvarchar(100)
projectserial int
There are indexes on projectname and projectserial
I want to generate a sequential projectserial per project as rows are added
eg:
0 | coffee shop | 7 Jan 2011 08:13 | derek | 0
1 | disco | 7 Jan 2011 08:18 | emma| 0
2 | coffee shop | 7 Jan 2011 08:19 | peter| 1
3 | disco | 7 Jan 2011 09:11 | alan| 1
4 | coffee shop | 7 Jan 2011 09:42 | tess | 2
So when retrieving the rows for a single project by projectname there is a persistent sequential serial number for each row specific to that projectname.
After inserting the row I currently do:
update projectlog set projectserial=1+
(select isnull(max(projectserial),0) from projectlog
where projectname='coffee shop') where (projectlogidentity=4);
but I’m worried about performance when this table will contain hundreds of thousands of rows and hundreds of projects. Is there a better way?
thanks
Derek
i think you can use two table for performance.