views:

2382

answers:

2

I need to disable some user accounts within a sql server version 2000. the following sql command is giving me an " incorrect syntax near 'Login' " error. The user name is valid and spelled correctly so I'm wondering if the command syntax is different for version 2000.

ALTER LOGIN exampleuser DISABLE
+5  A: 

SQL Server 2000 doesn't have the ALTER LOGIN statement. So to be able to disable the login you'll have to call the sp_denylogin procedure instead.

EXEC sp_denylogin 'exampleuser'

or

EXEC sp_revokelogin 'exampleuser'

To give them back access again you should use

EXEC sp_grantlogin 'exampleuser'

Note: sp_denylogin, sp_revokelogin and sp_grantlogin only works on Windows accounts and groups.

To be able to deny pure SQL Server logins, it seems like the only option is to remove that login completely with

EXEC sp_droplogin 'exampleuser'

but to enable it again, it needs to be re-created with

EXEC sp_addlogin 'exampleuser', 'examplepassword'

or just remove that logins access to the current database with

EXEC sp_revokedbaccess 'exampleuser'
Jimmy Stenke
Do you know what the command is to enable the account after it's been disabled?
MG
Is this method only valid for Windows NT user or groups?
MG
To be honest. I'm not entirely sure. They should apply to both SQL Server logins and Windows NT users.
Jimmy Stenke
This command fails when i try to use it on a non winders nt user :( msg: windows nt user or group 'exampleuser' not found. check the name again.
MG
hmm, ok, that I didn't know. Then I think the only option you can do is use the sp_droplogin procedure and remove the user login completely
Jimmy Stenke
Alternatively, you can remove the user from each of the databases with sp_revokedbaccess. That will stop them from entering any databases, even if they still can access the cluster.
Jimmy Stenke
Thank you for your help. much appreciated!
MG
+1  A: 

sp_revokelogin will remove the login entry. However , this proc has been deprecated in favour of drop login

But note that both of these will not disable the user but delete the login.

Your ALTER LOGIN approach is correct

ALTER LOGIN exampleuser DISABLE;

works with sql server 2008 atleast.

Learning
In SQL Server 2000 it is not deprecated, instead the only way to do it. CREATE LOGIN, ALTER LOGIN and DROP LOGIN was introduced in 2005
Jimmy Stenke