Wednesday, February 27, 2013

Auto generate numeric id in sql server table

USE tempdb
GO

CREATE TABLE Test(
CandID as 'C-' + RIGHT('000' + CONVERT(varchar, CourseID),5),
CourseID int IDENTITY(1,1),
ReferrerName varchar(10)
)

INSERT INTO Test VALUES ('MIKE')
INSERT INTO Test VALUES ('KELLY')
INSERT INTO Test VALUES ('NICK')
INSERT INTO Test VALUES ('James')
INSERT INTO Test VALUES ('Jones')
INSERT INTO Test VALUES ('Nick')

SELECT * FROM Test

Thanks

No comments:

Post a Comment

https://blog.sqlauthority.com/2009/06/27/sql-server-fix-error-17892-logon-failed-for-login-due-to-trigger-execution-changed-database-context...