Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Automaticly generate column value

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
Go to Top of Page

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

Go to Top of Page

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
Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page

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.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-07-31 : 11:53:58
quote:
Originally posted by blindman

Please re-read the post carefully. He is not looking for a simple Identity value.



Surrogate keys again...oye

http://weblogs.sqlteam.com/brettk/archive/2004/06/09/1530.aspx

Please post the table DDL that you have now



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-31 : 12:46:45
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57069


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -