Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如果存储过程的用户名为空,则阻止登录_Sql_Sql Server - Fatal编程技术网

Sql 如果存储过程的用户名为空,则阻止登录

Sql 如果存储过程的用户名为空,则阻止登录,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.

在数据库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.')
   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
}