Tuesday, February 3, 2015

Count Number of Columns in a Table and Delay in Sql server

Hi Geeks,

A simple query to find the number of columns in a table .

Here in example i have used Northwind  database table named as 'Categories' which returns the no of columns.

  1: use Northwind
  3: select count('c') 'Columns Count' from sys.syscolumns where id=object_id('Categories')


This is very simple ,it generally uses in lot of queries.

2. The second is very interesting fact about Sql server is that to put delay in your query execution or on demand execution of query after certain time or on any specified time.During execution of the WAITFOR statement, the transaction is running and no other requests can run under the same transaction.

Kindly find the depict image as an example.


I you notice at the right of the bottom ,it shows it took 10 seconds to print this message.

This is very cool feature could be used in your query only.WAITFOR can be used with query but not with UDF or cursors.

Hope will help you some where.

Enjoy Coding.

Sachin Kalia


Post a Comment