18/12/2012 by Nitesh

Solution: ExecuteNonQuery() always returning -1 when calling a Stored Procedure

Friends, This post details another solution to a very basic problem that we face in our development and tend to miss writing Stored Procedures. We know ExecuteNonQuery() function defined in the SqlCommand class returns the number of rows affected by the query we are executing. Sometimes, when calling a Stored Procedure using the ExecuteNonquery() from…

Continue Reading »

17/12/2012 by Nitesh

How to Retrieve File size of all Databases present in SQL Server on Hard Disk

Friends, In our previous post, we read about how can we get the file size of a SQL Server database on hard disk. In this post we will write a query that will return the file sizes of all the databases present on a SQL Server. Code below – CREATE TABLE #db_space ( [DBname] NVARCHAR(50),…

Continue Reading »

15/12/2012 by Nitesh

How to Retrieve the File Size used by a SQL Server Database on Hard Disk

Friends, We all work with databases and while working with databases, we all have most probably SQL Server one version or the another. Today, in this post we will see how to retrieve the size of data files of all databases present in SQL Server and the actual amount used in these files. As you…

Continue Reading »

29/11/2012 by Nitesh

How to Execute a Query Stored in a variable in Stored Procedure

Friends, Today, I was working with SQL Server and found an interesting situation where I wanted to store my query in a variable in stored procedure and after preparing the query based on parameters, execute the query at the last. I came up with an interesting solution for this. Let us consider the below stored…

Continue Reading »

12/09/2012 by Nitesh

How to Select a random row with Microsoft SQL Server

A quick post for all – We often find situations where we need to retrieve random records from a MS SQL table. The below query does the same for you. To generate a random record from a table in Microsoft SQL Server, we need to execute the following query: SELECT TOP 1 * FROM tbl_name…

Continue Reading »

1 2 3 4