Articles Posted in the " tsql " Category

  • How to Exclude Read_Only Databases Using sp_MSforeachdb

    How to Exclude Read_Only Databases Using sp_MSforeachdb

    I will explain how you can use sp_MSforeachdb stored procedure against READ_WRITE database only.

    There are numerous articles on the web about excluding databases using database id or name. Recently I needed a script to run against databases that are part of Always On Availability Groups and in READ_WRITE status. I used the ‘Updateability’ properties of DATABASEPROPERTYEX function.

    Here is how I implemented this.

    SET NOCOUNT ON
    
    EXEC sp_MSForEachDb '
    USE [?]
    IF ''?'' NOT IN (''master'', ''model'', ''msdb'', ''tempdb'', ''Distribution'') 
    IF ((SELECT DATABASEPROPERTYEX(''?'', ''Updateability''))=''read_write''  )
    BEGIN
    .....
    .....
    END
    '
    

    I would like to know if you implemented same …


  • TSQL Tuesday #79 -JSON Support in SQL 2016

    TSQL Tuesday #79 -JSON Support in SQL 2016

    I thank Michael J Swart (b|t) for hosting TSQL Tuesday #79. Topic for this month is to write about SQL Server 2016. This is my first time joining in TSQL Tuesday and I am excited about it.

    TSQL2SDAY-300x300

    In my workplace we use MongoDB besides SQL Server. MongoDB save documents in binary form of  JSON called BSON. Our developers are excited to see JSON support in SQL 2o16.  I will give some simple examples about JSON support in SQL Server 2016.  Readers need to be aware that SQL Server is not supporting native JSON type.  In …