That's probably what I would do. Create a trigger that checks the value that was inserted against both the username and loginname columns. You could do this through the third column suggested above (the trigger would insert new values from the two columns into the third), or you might be able to make a trigger that checks against the existing columns. Maybe something like this?:
declare @displayname varchar 255
declare @username varchar 255
declare @check int
--Get our variables from the "imaginary" Inserted table.
set @displayname = select distinct displayname from inserted
set @username = select distinct username from inserted
--Changing value, increments by one every time there is a match
set @check = 0
--Begin checks
if exists
select *
from t_user t (nolock)
where t.displayname = @displayname
begin
set @check = @check + 1
end
if exists
select *
from t_user t (nolock)
where t.displayname = @username
begin
set @check = @check + 1
end
if exists
select *
from t_user t (nolock)
where t.username = @displayname
begin
set @check = @check + 1
end
if exists
select *
from t_user t (nolock)
where t.username = @username
begin
set @check = @check + 1
end
--CHeck @check, rollback if name in use
if @check > 0
begin
raiserror("This username is already in use as a username or loginname", 16, 1)
rollback transaction
return
end
That code sucks and is probably going to give a DBA or two a conniption fit (I'm tired as hell), but it might give you an idea, or at least get you thinking of another possibility. Oh, and it's in T-SQL format, I'm not sure what "flavor" you use.
As everyone know, triggers can really destroy a DB's performance is used without caution, so be careful. I don't know of a way to create an index or constraint to do what you want to do... it sounds tough, good luck
