Sql 如果存储过程的用户名为空,则阻止登录
在数据库userrecord中,我有一个登录名为空的用户,这个用户只能使用密码登录到他的帐户。如何防止这种情况?并请告知?将其放入您的登录SPSql 如果存储过程的用户名为空,则阻止登录,sql,sql-server,Sql,Sql Server,在数据库userrecord中,我有一个登录名为空的用户,这个用户只能使用密码登录到他的帐户。如何防止这种情况?并请告知?将其放入您的登录SP if len(isnull(@LoginName,'')) = 0 -- or <@MinLoginNameLength if you wish Begin -- Select 'naughty, get a username' RAISERROR('%s',16,1,'cheaters never prosper.
if len(isnull(@LoginName,'')) = 0 -- or <@MinLoginNameLength if you wish
Begin
-- Select 'naughty, get a username'
RAISERROR('%s',16,1,'cheaters never prosper.')
end
这将有助于:
IF NULLIF(@LoginName, '') IS NULL ...
或
100%的工作
if(@LoginName IS NOT NULL OR @LoginName <> '')
{
-- Your Statement or your Query
}
请尝试此查询谢谢wheeler和sami。除了提供的答案外,我建议您更改您的表,以便用户名列不允许为null,这也值得使其唯一。您还可以添加检查约束,以便用户名值不能为空字符串。
if(@LoginName IS NOT NULL OR @LoginName <> '')
{
-- Your Statement or your Query
}