Friday 27 November 2015

Finding Recovery model of database

In our day to day activities  recovery model is a very important thing to be noted while dealing with database and appropriate recovery model should be set based on the requirement of the database , here lets see a few methods to find the recovery model of the databases

1)Database properties

    We can find the recovery model of a database by checking the option page in database properties, we can also change the recovery model form here,



2)Querying sys.databases view

    This is one of my favorite method as it offers me the flexibility of querying the required data like if i want to view only databases that are in full recovery i can query this view to get only the output i requires


3)Using built function databasepropertyex()

     We can find the recovery model by giving the databasename and recovery as parameter to this function  , databasepropertyex(database,recovery)




4)Viewing in object explorer details

     We can get recovery model of all the databases in an instance in object explorer details when we click on the database in object explorer, if the object explorer details in not visible we can make them visibile from view or by pressing shortcut 'F7'


Thursday 26 November 2015

Finding instances Installed in a server


In some situations we may need to find  the  instance installed in a server especially when some urgent request comes and we are not aware of the setup , so let me share a few methods i used to find the the instance names, i will be thankful if you can share me some other methods you follow

1)SQL Server Configuration manager

    This a much familiar method if we open sql server configuration manager we can see the instances installed in our server, in the below screenshot you can see the two instances in my system the default instance and the named instance'TEST'
We can open configuration manager from run for by giving below commands in run depending on the version
sqlservermanager11.msc -- SQL Server 2012
sqlservermanager10.msc -- SQL Server 2008
sqlservermanager.msc     --  SQL Server 2005





2)Services Console
 
  We can view the instance in system from services console which can be openend by giving services.msc in run ,in the below screenshot you can see the two instances in my system listed in services console



3)SQL cmd

   We can list the instances in our system using sqlcmd , for this we can use the command sqlcmd -L (L should be in upper case )in the command prompt, in the below snap shot you can see the instances in my system


4)Registry editor

  By navigating to the below given location in registry editor you can see the name of the instances installed in your server,
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL'
in the below screenshot you can see the two instances in my system





Sunday 1 November 2015

Reading error log with xp_readerrorlog


Most of us are used with reading error logs through GUI , but when we are really in looking for something in error logs TSQL may seems more use full , so lets look how to analyse log file using xp_readerrorlog

EXEC xp_readerrorlog a,b,c,d,e,f,g

a- Value of log file you want to read ,0 for current, 1 for Archived 1,2 for Archived 2 etc
b-We can chose between error log and agent log here
      1- for error log [default]
      2- for agent log
c-search string which you want to look in log
d-we can give one more string , this can refine the output we got by giving the search string C
e- Here we can from which time's log we want to search
f- Here we can give the to which time's log we want to search
g- Here we can specify whether we want output in ascending or descending order by specifying 'ASC'and 'DESC'

Lets have a look at few examples


Here this will query in Archive #1 error log and will search for logs with word "log" and which are logged after 2015-10-13 and will list the output in ascending order


In the above example we are querying in Archive#2 Agent log , it will search for logs containing both the search strings "error" and "network" which are logged between 2015-09-20 and 2015-09-24 and will list the output in descending order