Click here to Skip to main content
15,913,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to insert a custom generated value in a SQL table like S001,S002 like this.I have already created a table and i have column like userid in it.How can i auto insert the custom value whenever a record is inserted.
Posted

There are two options

1. Use trigger to generate the value. Using trigger[^]
2. If you are using this as a different field then you can compute if using identity field.Using alternative column[^]
 
Share this answer
 
Trigger will be best solution for this
 
Share this answer
 
Simple and good solution is DEFAULT.

1. Create a function which will return S001,S002 ect.
2. Set this function as Default in table design.

When you insert other values it will be fill automatically.

Almost same problem you can find from below link. Please take a look my comment below.
I need to insert a value based on year_num

Regards,
Vijay
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900