| Author |
Topic |
|
sarasahg
Starting Member
6 Posts |
Posted - 2006-07-30 : 04:33:36
|
| Hello ,I would like to know whether it is possible automatic generate values in primary column. I have learn from book that i can use identity to automatically generate value in the column when the data is inserted. Is it possible to automatically generate value for data type varchar. For example R0001. Looking forword to hear from u.Thank you |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-07-30 : 04:53:47
|
| No you can not directly do like this. Its better to this process in the front end, and then insert the value in the back end.Chirag |
 |
|
|
sponguru_dba
Yak Posting Veteran
93 Posts |
Posted - 2006-07-30 : 05:11:16
|
| Bigint,Decimal,int,numeric,smallint,tinyint are only Datatype allows Identities |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-07-30 : 06:20:11
|
| You could store the "R" in a different column, and the 1, 2, 3 ... in an identity column, and combine the two when you want to display the value.However, if every row will have the prefix "R" (rather than a range of possible values) then it wastes storage.You can have a COMPUTED column which would "convert" the IDENTITY column into "R000n", and that could be what you display to the user.Kristen |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2006-07-30 : 10:10:58
|
quote: Originally posted by chiragkhabaria No you can not directly do like this. Its better to this process in the front end, and then insert the value in the back end.Chirag
I have to disagree. It is possbile to do this using triggers or constraints, as Kristen has pointed out, and it is not inappropriate to do so. |
 |
|
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2006-07-31 : 01:18:51
|
| If u wants to generate values in Primary column, just mention IDENTITY property with proper SEED and INCREMENT. SQL2K will take care of it.Mahesh |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2006-07-31 : 10:42:09
|
| Please re-read the post carefully. He is not looking for a simple Identity value. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-07-31 : 12:46:45
|
| http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57069 MadhivananFailing to plan is Planning to fail |
 |
|
|
|