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 2005 Forums
 Transact-SQL (2005)
 Uniqueness Required

Author  Topic 

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-02-10 : 06:58:41
Hi..
Is there any way to ensure the uniqueness of any column.....
mean i just want that every value inserted in the table column is must be unique......

i just dont want any type of index,constraint and Identity Seed?


Mean i like to use constraint but it takes time when value inserted in this?
I Have a table in which when value is inserted then its update all the rows above and the minimum amount of rows above is 3 LAcks.....

so any body has any idea on this?

mean Ensure Uniqueness without using Index,Constraints and Identity Seed????

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-10 : 07:02:42
You can have a INSTEAD OF INSERT/UPDATE trigger to maintain uniqueness in table.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-02-10 : 07:04:25
To Ensure uniqueness for a table

insert into urtable(id,col2,col3-----)
select coalesce(max(id),0)+1,@col2,@col3---
from urtable

Jai Krishna
Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-02-10 : 07:36:02
I have Unique Values IN the Column 1 of Table A That needs to be inserted into Column 1 of Table B. Now I need Column 1 of Table B to be Made Unique Constraint without index on it.
Any Idea MAy Be U get My Requirement.
Thanks For Reply.

quote:
Originally posted by Peso

You can have a INSTEAD OF INSERT/UPDATE trigger to maintain uniqueness in table.



E 12°55'05.63"
N 56°04'39.26"


Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-10 : 07:38:58
You quoted me quite well, I think.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-02-10 : 07:39:26
After inserting into table B try the below code

insert into tableB(col1,col2,col3-----)
select max(col1)+1,@col2,@col3---
from tableB


Jai Krishna
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-10 : 09:28:13
quote:
Originally posted by Jai Krishna

After inserting into table B try the below code

insert into tableB(col1,col2,col3-----)
select max(col1)+1,@col2,@col3---
from tableB


Jai Krishna


how will this ensure uniqueness of id value?
Go to Top of Page
   

- Advertisement -