SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Check owners, collations and backups


Check owners, collations and backups

Author
Message
paul_richardson
paul_richardson
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1614 Visits: 215
Comments posted to this topic are about the item Check owners, collations and backups
dr.kusnadi
dr.kusnadi
SSC Veteran
SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)

Group: General Forum Members
Points: 210 Visits: 472
I can't see the script. is this only me?
paul_richardson
paul_richardson
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1614 Visits: 215
hi,
the script seems to have disappeared. I've re-added it, but it will be a few days until it's approved, So check back then.

Thanks

Paul
dr.kusnadi
dr.kusnadi
SSC Veteran
SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)SSC Veteran (210 reputation)

Group: General Forum Members
Points: 210 Visits: 472
Thanks Paul. Smile
Gennadi Gretchkosiy-440661
Gennadi Gretchkosiy-440661
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 13
Hi

The script

-- check whether database owners are valid
select name into #check_database_owners
from master.dbo.sysdatabases
where isnull(suser_sname(sid),'no_owner') = 'no_owner'


doesn't look like a valid.

This one works better:

IF SUBSTRING(@@version,23,4)='2000'
select SD.name as DBname,
suser_sname(SD.sid) as DBowner,
SL.name as USERname,
'Notfor2000' as LOGINname,
DD.name as DEFAULTdatabase
from master.dbo.sysdatabases SD left join master.dbo.sysxlogins SL
on SD.sid = SL.sid
left join master.dbo.sysdatabases DD on SL.dbid = DD.dbid
WHERE SL.name is null
ELSE
select SD.name as DBname,
suser_sname(SD.owner_sid) as DBowner,
SL.name as USERname,
SL.loginname as LOGINname,
SL.dbname DEFAULTdatabase
from master.sys.databases SD left join master.sys.syslogins SL
on SD.owner_sid = SL.sid
WHERE SL.name is null

Gennadi Gretchkosiy-440661
Gennadi Gretchkosiy-440661
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 13
Orphan users should be considered as well

CREATE TABLE #Results
([Database Name] sysname COLLATE Latin1_General_CI_AS,
[Orphaned User] sysname COLLATE Latin1_General_CI_AS)

SET NOCOUNT ON

DECLARE @DBName sysname, @Qry nvarchar(4000)

SET @Qry = ''
SET @DBName = ''

WHILE @DBName IS NOT NULL
BEGIN
SET @DBName = (SELECT MIN(name)
FROM master..sysdatabases
WHERE name NOT IN
('master', 'model', 'tempdb', 'msdb',
'distribution', 'pubs', 'northwind')
AND DATABASEPROPERTY(name, 'IsOffline') = 0
AND DATABASEPROPERTY(name, 'IsSuspect') = 0
AND name > @DBName)

IF @DBName IS NULL BREAK
IF SUBSTRING(@@version,23,4)='2000'
SET @Qry = ' SELECT ''' + @DBName + ''' AS [Database Name],
CAST(name AS sysname) COLLATE Latin1_General_CI_AS AS [Orphaned User]
FROM ' + QUOTENAME(@DBName) + '..sysusers su
WHERE su.islogin = 1
AND su.name <> ''guest''
AND NOT EXISTS
(
SELECT 1
FROM master..sysxlogins sl
WHERE su.sid = sl.sid
)'
ELSE
SET @Qry = ' SELECT ''' + @DBName + ''' AS [Database Name],
CAST(name AS sysname) COLLATE Latin1_General_CI_AS AS [Orphaned User]
FROM ' + QUOTENAME(@DBName) + '..sysusers su
WHERE su.islogin = 1
AND (su.name <> ''guest''
AND su.name <> ''INFORMATION_SCHEMA''
AND su.name <> ''dbo''
AND su.name <> ''sys'')
AND NOT EXISTS
(
SELECT 1
FROM master..syslogins sl
WHERE su.sid = sl.sid
)'


print @Qry
INSERT INTO #Results EXEC (@Qry)
END

SELECT *
FROM #Results
ORDER BY [Database Name], [Orphaned User]

DROP TABLE #Results

Rudy Panigas
Rudy Panigas
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2428 Visits: 1322
Hmm, I seem to be getting errors when executing the code.

Msg 207, Level 16, State 1, Line 2
Invalid column name 'object_id'.
Msg 102, Level 15, State 1, Procedure sp_common_server_problems, Line 31
Incorrect syntax near ' '.
Msg 102, Level 15, State 1, Procedure sp_common_server_problems, Line 130
Incorrect syntax near ' '.
Msg 102, Level 15, State 1, Procedure sp_common_server_problems, Line 132
Incorrect syntax near ' '.
Msg 102, Level 15, State 1, Procedure sp_common_server_problems, Line 142
Incorrect syntax near ' '.
Msg 102, Level 15, State 1, Procedure sp_common_server_problems, Line 144
Incorrect syntax near ' '.
Msg 102, Level 15, State 1, Procedure sp_common_server_problems, Line 156
Incorrect syntax near ' '.
Msg 156, Level 15, State 1, Procedure sp_common_server_problems, Line 161
Incorrect syntax near the keyword 'select'.
Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'sp_common_server_problems'.

Anyone have the same problem or know of how to fix this?



Rudy Panigas
Rudy Panigas
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2428 Visits: 1322
I'm having the same errors. Does anyone have the updated script? With Orphan reporting too?



paul_richardson
paul_richardson
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1614 Visits: 215
hi,
I'll post an updated version of this script at the weekend.

Paul
boris_shvartsman
boris_shvartsman
SSC-Enthusiastic
SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)

Group: General Forum Members
Points: 108 Visits: 200
This procedure doesn't work. It has a syntax error..

if one wants it.. one will justify it.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search