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 2000 Forums
 SQL Server Development (2000)
 Trouble with constraint

Author  Topic 

mAdMaLuDaWg
Starting Member

42 Posts

Posted - 2004-08-18 : 21:54:07
I'm having trouble with a constraint, here is my constraint expression on TempUserDB:
CONSTRAINT CK_CHECKUNIQUEUSERNAME CHECK ([dbo].[CheckUniqueUsername]([Username]) = 0)

Here is my function:
CREATE FUNCTION dbo.CheckUniqueUsername(@Username varchar(50))
RETURNS int
AS
BEGIN
DECLARE @UserCount int
Select @UserCount=count(*) from vwUserCheck where UserName=@Username
Return @UserCount
END


And finally, here is my view:
CREATE VIEW dbo.vwUserCheck
AS
SELECT dbo.TempUserDB.Username, dbo.TempUserDB.Email
FROM dbo.TempUserDB
UNION
SELECT dbo.UserDB.Username, dbo.UserDB.Email
FROM dbo.UserDB


The problem is that whenever I insert anything a user in the TempUserDB, the constraint somehow fails, although all tables are empty.
What am I doing wrong?

As always, the help is much appreciated.
   

- Advertisement -