You'd have to not use an IDENTITY column, but generated the ids/strings yourself.
Far better to format the IDENTITY column for display instead, especially if the string part is constant for all records - makes indexing/querying more performance and saves on db space.
If records may have a different string section (i.e. not all starting with "ABCD-"), then you could store that as a separate field.
No but you can create your Select statement in such a way as to return the code you want:
Select 'ABCD-' + Cast(IdColumn as varchar) as IdColumn From MyTable Where (....);
This assumes that you have a column called IdColumn in your table and that the "IDENTITY" property has been set to "true". That is, highlight the field in the table designer of SQL Server Management Studio and you'll see a window for the properties at the bottom.
If the 'ABCD' part may change, you could place this value in another field and then retrieve as so:
Select PrefixField + '-' + Cast(IdColumn as varchar) as IdColumn From MyTable Where (....);
You could, of course, create a View to do this for you or even a computed field as well. That way, the return value is built in to the query and you don't have to remember to enter all of this each time.
Nope, sorry. The identity "property" can only be placed on columns with the integer or decimal data type.
You'd have to not use an IDENTITY column, but generated the ids/strings yourself.
Far better to format the IDENTITY column for display instead, especially if the string part is constant for all records - makes indexing/querying more performance and saves on db space.
If records may have a different string section (i.e. not all starting with "ABCD-"), then you could store that as a separate field.
You could increment your string values with a function like this:
http://www.sqlservercentral.com/scripts/Miscellaneous/31448/
I'm curious, though, why you're looking to use an alpha-numeric key rather than just a numeric one.
No but you can create your Select statement in such a way as to return the code you want:
This assumes that you have a column called IdColumn in your table and that the "IDENTITY" property has been set to "true". That is, highlight the field in the table designer of SQL Server Management Studio and you'll see a window for the properties at the bottom.
If the 'ABCD' part may change, you could place this value in another field and then retrieve as so:
You could, of course, create a View to do this for you or even a computed field as well. That way, the return value is built in to the query and you don't have to remember to enter all of this each time.
In addition to the other answers, you could create a computed column on the table to provide what you are asking for.
Or:
(Your question doesn't say whether the prefix is intended to be fixed or not...)