How do i produce a Primary Type in SQL Server 2005/2008 using the format:
CurrentYear + auto-increment?
Example: The present year is 2010, inside a new table, the ID should begin in 1, so: 20101, 20102, 20103, 20104, 20105... and so forth.
Unsure exactly what you're attempting to accomplish by doing that, however it makes much more sense to get this done with two fields.
When the combination of these two should be the PK for whatever reason, just span it across both posts. However, it appears unnecessary because the identity part is going to be unique exclusive of the season.
This technically meets the requirements of that which you asked for:
CREATE TABLE #test ( seeded_column INT IDENTITY(1,1) NOT NULL , year_column INT NOT NULL DEFAULT(YEAR(GETDATE())) , calculated_column AS CONVERT(BIGINT, CONVERT(CHAR(4), year_column, 120) + CONVERT(VARCHAR(MAX), seeded_column)) PERSISTED PRIMARY KEY , test VARCHAR(MAX) NOT NULL); INSERT INTO #test (test) SELECT 'Badda' UNION ALL SELECT 'Cadda' UNION ALL SELECT 'Dadda' UNION ALL SELECT 'Fadda' UNION ALL SELECT 'Gadda' UNION ALL SELECT 'Hadda' UNION ALL SELECT 'Jadda' UNION ALL SELECT 'Kadda' UNION ALL SELECT 'Ladda' UNION ALL SELECT 'Madda' UNION ALL SELECT 'Nadda' UNION ALL SELECT 'Padda'; SELECT * FROM #test; DROP TABLE #test;
You need to write a trigger with this :)
Possess a separate table for storing the final digit used (I truly have no idea whether there's something such as sequences in Oracle in SQL Server).
You will get the final item placed item and extract the final quantity of it.
You will get the present year from
The trigger will be a
ON INSERT trigger in which you mix the entire year and also the last digit increase the column