Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am presently using identity function on columns to generate values but i donot find it good . is there any function in sql sever which converts numbers in strings so that i can assign to column . i mean i want to add value such that c1 or say c102 or anything like that in primary key column.

is there any way to generate an unique value for primary key column.any functions/stored procedures or triggers

also i am using triggers to add values from old tables to new tables when ever there is update/insert or delete on old table . i am using following syntax but i am geeting error so please help

my syntax is

SQL
create trigger <triggername> on <tablename>
after insert 
as begin
  insert into triggertable values(:old.tablecolumn1,:old.tablecolumn2,.....)
end
</tablename></triggername>

i am getting error for above syntax such as "error at : or old.tablecolumn" is not permitted .
Posted
Updated 8-Nov-11 5:05am
v3

It is better to define your primary keys as integer type for performance and create a "more readable" column in the format your require to show to your users.

EDIT:

Read this also : http://stackoverflow.com/questions/4821831/sql-server-generate-primary-key-based-on-counter-and-another-column-value[^]
 
Share this answer
 
v2
Comments
Dylan Morley 8-Nov-11 11:22am    
Agreed + nice link, funny comments!
Mehdi Gholam 8-Nov-11 11:26am    
Thanks Dylan.
I think your problem will be solved by computed fields , and your problem is very similar to this person :

Auto Number pls help[^]

Hope it helps.
 
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