November 27, 2008 at 11:00 pm
Hi
I have a table with col_id and col_emailid and i want to make col_emailid as unique. But ,
col_id col_emailid
should not be allowed but
1/2/3 kk@abc.com
should be allowed
i.e if col_id = 0 then col_emailid can exists twice
else not.
Please help as what can i do. I cant make the two col as unique key also
November 28, 2008 at 12:32 am
I'm not sure there's a good way in SQL 2005.
Why can't you make the combination of the two columns unique?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 28, 2008 at 12:34 am
GilaMonster (11/28/2008)
I'm not sure there's a good way in SQL 2005.Why can't you make the combination of the two columns unique?
I cant make combination as unique coz 1. abc and 2.abc is not allowed. Please read my first post carefully
November 28, 2008 at 12:54 am
I read your first post just fine, thank you.
Is the 2-column key just because of that, or is there another reason you can't have a 2-column unique key (with different columns). You didn't say.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 28, 2008 at 1:12 am
Try this trigger
CREATE TRIGGER dbo.trgZeroUnique ON dbo.Table1
AFTERINSERT,
UPDATE
AS
IF EXISTS (SELECT eMail FROM Table1 GROUP BY eMail HAVING COUNT(*) > 1 AND MIN(ID) > 0)
BEGIN
ROLLBACK TRANSACTION
RAISERROR('Duplicate eMail found.', 16, 1)
END
N 56°04'39.16"
E 12°55'05.25"
November 28, 2008 at 6:39 pm
khushbu.kumar (11/28/2008)
GilaMonster (11/28/2008)
I'm not sure there's a good way in SQL 2005.Why can't you make the combination of the two columns unique?
I cant make combination as unique coz 1. abc and 2.abc is not allowed. [font="Arial Black"]Please read my first post carefully[/font]
Heh... pretty damned rude for someone who needs help. Stop being so bloody arrogant and you'll get a lot more help. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
November 28, 2008 at 6:41 pm
BWAA-HAA! And then, you double post the same question...
http://www.sqlservercentral.com/Forums/Topic610096-146-1.aspx
... you're not making a lot of friends here.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply