I have database table named Form with 2 columns Id and UserName.
I have created view on the table which is having columns Id and UserName.
On that view I have created UNIQUE CLUSTERED INDEX for column UserName So, that whenever user try to insert duplicate value for UserName it will throw unique constraint violation exception.
Is there any way to achieve below requirement,
I need to append an incremented integer to make the UserName unique.
When user enter UserName which is already present in table it should append incremented integer to it.
When inserting Username , we don't always just append a "1" to the end.
I need to append an incremented integer to make the UserName unique.
This matches the behavior of Windows when copying files.
If user inserts "Tom" 3 times, then it should create "Tom 1", "Tom 2", and "Tom 3".
If the user inserts "Tom" again, then it should create "Tom 4".
Again Think about this:
If user manually inserts "Tom" and "Tom 2"
The user then inserts "Tom" - it should create "Tom 1".
The user then inserts "Tom" again - it should create "Tom 3" because "Tom 2" already exists.
Its similar windows file directory. When we copy/pasting text document in some folder it over and over.
I need this functionality to achieve unique name in CQRS with EventSourcing ,C# application where When user copies some entity eg. FormName it should just append incremental integer to FormName on basis of FormNames present in Db and can return from db So, that we can show new FormName on UI.
TRY...CATCH
block? – Sam cd