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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 primarykey with string

Author  Topic 

desikankannan
Posting Yak Master

152 Posts

Posted - 2011-12-23 : 01:14:10
Hi,
i wants to add primary key with string

example
1a
1b
1c

below i built but it holds duplication value

select N_WalkerId as id ,v_name as name,'walkers' as usertype,case B_Status when 1 then 'Active' else 'InActive' End As status from tblWalkerDetails where V_name like '%" + a + "%' union select n_ownerid as id,v_name as name ,'pet' as usertype,case B_Status when 1 then 'Active' else 'InActive' End As status from tblPetOwner where V_Name like '%" + a + "%' union select N_PetId as id, v_petname as name ,'client' as usertype,case B_Status when 1 then 'Active' else 'InActive' End As status from tblpetdetails where V_PetName like '%a'

looking for reply


Desikankannan

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-23 : 01:18:12
just use ALTER TABLE <tablename> ADD CONSTRAINT...

to add the PK
so far as the string values are unique it wont cause any issues

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

desikankannan
Posting Yak Master

152 Posts

Posted - 2011-12-23 : 01:36:32

iam using auto search option it repeats duplicate that why i want to concoct example

1 wakers
1 owners
1 client

its come 3 times 1


quote:
Originally posted by visakh16

just use ALTER TABLE <tablename> ADD CONSTRAINT...

to add the PK
so far as the string values are unique it wont cause any issues

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Desikankannan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-23 : 01:57:51
but concatenated values is unique right? then it wont cause any issues

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

desikankannan
Posting Yak Master

152 Posts

Posted - 2011-12-23 : 02:07:59
but i don't how to concocted
i need to 1w,1c,1o

quote:
Originally posted by visakh16

but concatenated values is unique right? then it wont cause any issues

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Desikankannan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-23 : 03:14:38
just do like

cast(col1 as varchar(10)) + col2

to concatenate bothe their values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -