SQL Server General DBA

Verify Whether a SQL Server Agent Job is Running

When I posted an faq about Finding Running SQL Server Agent Jobs I had several few emails and queries on how verify whether a job is running by using only a TSQL script. The below script will verify if the job exists and whether or not it is running. DECLARE @jobname sysname =’Running Job’ — […]

Finding Running SQL Server Agent Jobs

Monitoring SQL Server agent jobs is a critical task for DBAs. There are several ways of achieving this. The most obvious method is to use the Job Activity monitor. For the above list, note that the currently running jobs will have a green arrow icon next to them. However, if you have large number of […]

How to Differentiate System and User Databases In SQL Server

This question is frequently asked in many forums and the most popular answer is to use the DB_ID() function as shown below. So if you want to get only the system databases you can use DB_ID(databasename) < 5 in your where clause. This work around is used since there is no dedicated column in sys.databases […]

SQL Server 2014 Security Enhancements : User Object Permissions

In many database systems, it is a requirement to grant read permission for all databases. To achieve this, there is no other way but grant read permission to each and every database. Let’s first create a login : CREATE LOGIN [newUser] WITH PASSWORD=N’P@$$w0Rd’ GO The login is created without any issues, and you can login […]

Importing data from text file to specific columns using BULK INSERT

Bulk insert is much faster than using other techniques such as  SSIS. However, when you are using bulk insert you can’t insert to specific columns. If, for example, there are five columns in a table you should have five values for each record in the text file you are importing from. This is an issue […]

Drop Failed for Login ‘User xxx’

How To Drop Users Who Are Owners or Databases and Jobs When you want to drop users you need to en sure that those users are not owners databases SQL Server agent jobs, otherwise you will be confronted with the below error: To avoid this you will need to change both the database and SQL […]

Drop a Database by Closing Existing Connections using SSMS or T-SQL

To drop a SQL Server database, you will need exclusive access to the database ensure there are no other current users of the database or you will encounter the error: Drop failed for Database ‘dbName’ …. Cannot drop database because it is currently in use Ensuring there are no other current users can be very […]

Configuring Email in SQL Server 2000

A couple of days back I was asked to configured database email for a DB Server which was hosted on a SQL Server 2000 environment. Configuring a database email in SQL Server 2000 is somewhat different than the SQL Server 2005 environment as there is no GUI available in SQL Server 2000. The following steps […]

Altering a Column Which has a Default Constraint

Setting up a default column is a common task for  developers.  But, are we naming those default constraints explicitly? In the below  table creation, for the column, sys_DateTime the default value Getdate() will be allocated. CREATE TABLE SampleTable (ID int identity(1,1), Sys_DateTime Datetime DEFAULT getdate() ) We can check the relevant information from the system […]

Troubleshooting High-CPU Utilization for SQL Server

The objective of this FAQ is to outline the basic steps in troubleshooting high CPU utilization on  a server hosting a SQL Server instance. The first and the most common step if you suspect high CPU utilization (or are alerted for it) is to login to the physical server and check the Windows Task Manager. […]