How to stop users from entering same uid nad pwd | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

How to stop users from entering same uid nad pwd

I have a table in which I have created a username and a password coloumn.I am wondering how is it possible to restrict users from entering same username and password.That s username should not be equal to password.Management want that this restriction should be given in database.Though we have this restriction in frontend (a javascript program).Even then also my manager wants in backend.How can I accomplish this [xx(]
Can take help of triggers and constraints in this regard. Satya SKJ
Moderator
http://www.SQL-Server-Performance.Com/forum
This posting is provided “AS IS” with no rights for the sake of knowledge sharing.
Unfortunately you can’t use a CHECK constraint in your case. So, your only way would be a trigger. —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Ich unterstütze PASS Deutschland e.V. http://www.sqlpass.de)

A quick and dirty example of such a trigger might look like:
create table t
(c1 int
, c2 int
)
go
create trigger dbo.testme on t for insert
as
declare @i int
if exists(select * from inserted i where i.c1=i.c2)
begin
select @i=i.c2 from inserted i
print @i
rollback tran end
go
insert into t select 1,1
go
insert into t select 1,2
go
select * from t
drop table t The first INSERT fails and is rolledback, while the second INSERT will succeed. —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Ich unterstütze PASS Deutschland e.V. http://www.sqlpass.de)

]]>