Welcome to SQLDBcontrol Forums Sign in | Join | Help
in

Checking that all databases are in source control

Last post 11-06-2009, 15:10 by ddriver. 2 replies.
Sort Posts: Previous Next
  •  11-05-2009, 21:14 307

    Checking that all databases are in source control

    We have several several servers that host our data. I looked for a way to validate what was in source control and what was not. I put together this script. You will have to to a little editing to make it work for you but it may be helpful.


    -- get the list of dbs and servers fro source control
    IF OBJECT_ID('tempdb..#sc') IS NOT NULL DROP TABLE #sc
    SELECT DISTINCT o.ServerName, o.DatabaseName, ps.ProjectName
    INTO #sc
    FROM SQLDBControl.dbo.DatabaseObject o
    JOIN SQLDBControl.dbo.ProjectServerDBObject psdo ON psdo.ObjectId = o.ObjectId
    JOIN SQLDBControl.dbo.ProjectServerDatabase psd ON psd.ServerDbId = psdo.ServerDbId
    JOIN SQLDBControl.dbo.ProjectServer ps ON ps.ProjectServerId = psd.ProjectServerId
    ORDER BY o.ServerName, o.DatabaseName, ps.ProjectName

    -- get the list of databases for the servers
    IF OBJECT_ID('tempdb..#db') IS NOT NULL DROP TABLE #db
    CREATE TABLE #db (ServerName VARCHAR(255), DatabaseName VARCHAR(255))
    INSERT #db SELECT 'ServerA', Name FROM ServerA.master.sys.databases
    INSERT #db SELECT 'ServerB', Name FROM ServerB.master.sys.databases
    INSERT #db SELECT 'ServerC', Name FROM ServerC.master.sys.databases

    -- delete the system and report databases
    DELETE FROM #db
    WHERE DatabaseName IN ('master'
    , 'model'
    , 'msdb'
    , 'ReportServer'
    , 'ReportServerTempDB'
    , 'RSExecutionLog'
    , 'tempdb') -- system and reporting databases

    -- how many are there?
    SELECT DatabaseName, COUNT(*) [Count]
    FROM #db
    GROUP BY #db.DatabaseName
    ORDER BY COUNT(*) DESC


    -- who is under control and who is not?
    SELECT d.ServerName
    , d.DatabaseName
    , CASE
    WHEN s.ServerName IS NULL
    THEN 'Uncontrolled'
    ELSE 'Controlled'
    END AS UnderControl
    FROM #db d
    LEFT OUTER JOIN #sc s
    ON s.ServerName = d.ServerName
    AND s.DatabaseName = d.DatabaseName
    ORDER BY d.ServerName, d.DatabaseName
  •  11-05-2009, 23:02 312 in reply to 307

    Re: Checking that all databases are in source control

    Thanks,

    It looks like this would work by prompting for a list of servers to check and/or automatically checking any servers that are already registered in a project.

    We could also extend this to provide, for those databases that are under source control, a count of objects that are and aren't under source control. Which could provide a higher level report to the Difference Report.
    SQLDBcontrol Support

    support@sqldbcontrol.com
  •  11-06-2009, 15:10 315 in reply to 312

    Re: Checking that all databases are in source control

    This in't necessarily a feature I am asking you to add. I just though the functionality would be helpful for other admins.

    If this is something you eventually want to include, feel free to do so. We have many projects, 70 databases, and six servers. This was to fill the need of we knew that there had to be databases that were not in a project somewhere.
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems