SQL Server 2000 Administration tips

Rate this:
By AndrewGail (Contact - View My Woyano)
Published Wed 11 Apr 2007, 409 Views, 3 Comments

Here are a few handy SQL commands that you may find useful (for SQL Server 2000).

Have you ever needed to list all databases on the current instance of SQL Server? You've probably not but this code will do it all the same ;)

exec sp_MSforeachDB "sp_helpdb ?"

What about listing detached users?  Detached users are common when doing incomplete restores where the master database is corrupt:

exec sp_change_users_login 'Report'

Fixing your detached users could not be simpler, you can attempt to automatically fix all users:

exec sp_change_users_login 'Auto_Fix'

This instructs SQL Server to make a best guess at which database users match which logins, I find this rarely works well and in some instances won't work at all, so a manual approach is usually better:

exec sp_change_users_login 'Update_One', 'DemoUser', 'DemoLogin'

Here we are telling SQL Server to pair the database user DemoUser with the system login DemoLogin.

 

I Hope this is of some use to somebody, I'll check back and update this page every now and again with more useful tips.

 

- Andy



This Item
Category: Knowledge, Snippets, Computers
Tags: SQL, SQL Server, detatched user, database, show databases
Contributor
AndrewGail
Share it
Link to this item:
Bookmark this item: RSS Feed

People who liked this item

    3 Comments

  1.  
    georgie ~ 17 months ago
    0 votes thumbs up thumbs down
    Thanks Andy. To find other useful tips in this category, keyword search for "SQL".

    Did you know that posts like this go straight to your MyWoyano page? It's your space to highlight your unique skills and knowledge. Drive traffic to your own webpage from the Woyano audience. Have a look at Andy's page, www.woyano.com/AndrewGail
    [ reply ]
    1.  
      JV ~ 17 months ago
      0 votes thumbs up thumbs down
      Hiya, what database are we talking about here? :)
      [ reply ]
      1.  
        AndrewGail ~ 17 months ago
        0 votes thumbs up thumbs down
        Hi JV, sorry I should've made it more clear. These are SQL Server 2000 stored procedures ;)
        [ reply ]
        1.  
          22 votes thumbs up thumbs down
          This is my two cents...

             
          Hey you know AdGuy always gets the last word! ;)

        Please Login to Add Your Comment   ..or..  

        Replying to comment by