Posted by Mohammed Mawla on Jan 24, 2012
A frequent inquiry concerning databases’ security is to retrieve the database role(s) associated with each user for auditing or troubleshooting purposes.
Each database user (principal) can be retrieved from sys.database_principals and the associated database roles can be retrieved from sys.database_role_members
The following code runs against ALL the databases using SP_MSForeachdb and all roles for one principal is concatenated in one row Read the rest of this entry . . .
Posted by Mohammed Mawla on Oct 19, 2011
If you ever participated in some forum or message board , then you know what’s BBCode.
What’s BBCode ?
BBCode is short for Bulletin Board Code and used to format posts in forums or message boards as a fast way to achieve formating without the need to add any complex HTML code beside allowing safer posts (no JS code for example). BBCode uses tags indicated by rectangular brackets surrounding a keyword. At the time of displaying as part of a webpage , those tags are converted to HTML.
A simple example of BBCode would be to make some text bold , this can be simply written like that [b]Bold Text[/b] or italic [i]italic text[/i]. In HTML , this can be done by font tags (deprecated in newer HTML versions) or CSS text properties. I tell you what! I’m writing this blog and I’m even using some BBCode tags to format text. Read the rest of this entry . . .
Posted by Mohammed Mawla on Nov 3, 2009
It is not unusual that a DBA needs to run the same query across multiple instances. The query can be anything from a simple line to retrieve a specific value (such as an instance version), to others that involve data modifications or schema changes.
SQL Server 2008 brought the ability to execute Statements Against Multiple Servers Simultaneously by simply creating a local server group or broadly using a Central Management Server and one or more server groups. Inside these groups there should be one or more registered servers.
There is also the commercial Red-Gate SQL Multi Script with an Unlimited edition license that allows you to run your code against any number of SQL server instances.
Before SQL Server 2008, there was no native support for running the same query against multiple instances using shipped tools, so it can be approached in one of these ways: Read the rest of this entry . . .
Posted by Mohammed Mawla on Mar 12, 2009
In SQL Server Replication, a regular check is getting the number of undistributed commands for a transactional subscription. This can be done using the replication monitor (SQlmonitor.exe from the RUN prompt) or programmatically by running sp_replmonitorsubscriptionpendingcmds at the Distributor on the distribution database.
One issue with sp_replmonitorsubscriptionpendingcmds is that you will have to submit a few parameters without defaults (the required parameters are mentioned in the above link).
I wanted once to get status information about all subscriptions (Last logged message, status, agent, etc.), plus the number of undistributed commands for each subscription. For the replication info there is the MSdistribution_agents table, which is stored in the Distribution database and contains one row for each Distribution Agent. For the Agents’ history there is the MSdistribution_history table, which contains the history for Distribution agents, and is also stored in the Distribution database.
To return this, my idea was to get a list of publishers, publications, subscribers, and so on, into a temporary table, loop against the result, and run sp_replmonitorsubscriptionpendingcmds for each row, and then join against MSdistribution_history for the final result.
Here it is. All comments and additions are welcome.
Read the rest of this entry . . .