Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

SQL Server – Different Ways to Check Object Definition

sp_helptext is widely used for checking object definition in SQL Server. sp_helptext can be used to check definition of various database objects like Views, Stored Procedures and User Defined Functions.

There are two other options which can be used to retrieve object definition:

OBJECT_DEFINITION( object_id ) – is a built-in… Read more

2 comments, 634 reads

Posted in SQL and Me on 14 April 2014

SQL Server – Different Ways to Check Object Definition

sp_helptext is widely used for checking object definition in SQL Server. sp_helptext can be used to check definition of various database objects like Views, Stored Procedures and User Defined Functions.

There are two other options which can be used to retrieve object definition:

OBJECT_DEFINITION( object_id ) – is a built-in… Read more

2 comments, 57 reads

Posted in SQL and Me on 14 April 2014

SQL Server – Hide system objects in Object Explorer – SQL Server Management Studio

By default, SQL Server system objects are listed in Object Explorer in Management Studio. These system objects include system database, system tables/views/procedures and so on.

SQL Server Management Studio provides an option to hide these objects from Object Explorer to prevent *accidental* use.

To enable this option follow below steps. Read more

1 comments, 59 reads

Posted in SQL and Me on 7 April 2014

SQL Server – Hide system objects in Object Explorer – SQL Server Management Studio

By default, SQL Server system objects are listed in Object Explorer in Management Studio. These system objects include system database, system tables/views/procedures and so on.

SQL Server Management Studio provides an option to hide these objects from Object Explorer to prevent *accidental* use.

To enable this option follow below steps. Read more

1 comments, 2,610 reads

Posted in SQL and Me on 7 April 2014

SQL Server – How to get last access/update time for a table

Modify date and create date for a table can be retrieved from sys.tables catalog view. When any structural changes are made the modify date is updated. It can be queried as follows:


USE [SqlAndMe]
GO

SELECT    [TableName] = name,
create_date,
modify_date
FROM    sys.tables
WHERE    name = 'TransactionHistoryArchive'
GO

 

  Read more

2 comments, 1,976 reads

Posted in SQL and Me on 11 March 2014

SQL Server – How to get last access/update time for a table

Modify date and create date for a table can be retrieved from sys.tables catalog view. When any structural changes are made the modify date is updated. It can be queried as follows:


USE [SqlAndMe]
GO

SELECT    [TableName] = name,
create_date,
modify_date
FROM    sys.tables
WHERE    name = 'TransactionHistoryArchive'
GO

 

  Read more

2 comments, 44 reads

Posted in SQL and Me on 11 March 2014

SQL Server – Displaying line numbers in Query Editor – SSMS

You can enable line numbers to be displayed in SSMS Query Editor. This is extremely useful when working on a large module.

To enable line numbers in Query Editor windows, follow below steps:

Step1: Go to Tools > Options

Step2: In the Options dialog box navigate to Text Editor >… Read more

0 comments, 47 reads

Posted in SQL and Me on 20 January 2014

SQL Server – Displaying line numbers in Query Editor – SSMS

You can enable line numbers to be displayed in SSMS Query Editor. This is extremely useful when working on a large module.

To enable line numbers in Query Editor windows, follow below steps:

Step1: Go to Tools > Options

Step2: In the Options dialog box navigate to Text Editor >… Read more

0 comments, 543 reads

Posted in SQL and Me on 20 January 2014

SQL Server – Difference between @@CONNECTIONS and @@MAX_CONNECTIONS

@@MAX_CONNECTIONS in SQL Server returns maximum number of simultaneous user connections allowed. Maximum user connections allowed by SQL Server by default is 32,767; this number also depends on application and server hardware limits. This cam also be configured at server-level to avoid too many connections.

@@CONNECTIONS returns number of connection… Read more

0 comments, 756 reads

Posted in SQL and Me on 13 January 2014

SQL Server – Difference between @@CONNECTIONS and @@MAX_CONNECTIONS

@@MAX_CONNECTIONS in SQL Server returns maximum number of simultaneous user connections allowed. Maximum user connections allowed by SQL Server by default is 32,767; this number also depends on application and server hardware limits. This cam also be configured at server-level to avoid too many connections.

@@CONNECTIONS returns number of connection… Read more

0 comments, 44 reads

Posted in SQL and Me on 13 January 2014

SQL Server – Different ways to check Recovery Model of a database

A Recovery Model is property of a database which control how transaction log is maintained. SQL Server supports SIMPLE, FULL and BULK-LOGGED recovery models.

There are multiple ways to check recovery model of a database in SQL Server.

1. Using SQL Server Management Studio:

Right click on Database in… Read more

1 comments, 45 reads

Posted in SQL and Me on 6 January 2014

SQL Server – Different ways to check Recovery Model of a database

A Recovery Model is property of a database which control how transaction log is maintained. SQL Server supports SIMPLE, FULL and BULK-LOGGED recovery models.

There are multiple ways to check recovery model of a database in SQL Server.

1. Using SQL Server Management Studio:

Right click on Database in… Read more

1 comments, 1,611 reads

Posted in SQL and Me on 6 January 2014

SQL Server – Calculating elapsed time from DATETIME

Elapsed time can be calculated from DATETIME field by extracting number of hours/minutes and seconds. You can use below query to calculate elapsed time between two dates:

-- Vishal - http://SqlAndMe.com

DECLARE @startTime DATETIME
DECLARE @endTime DATETIME

SET @startTime = '2013-11-05 12:20:35'
SET @endTime = '2013-11-10 01:22:30'

SELECT	[DD:HH:MM:SS] =…

Read more

8 comments, 4,971 reads

Posted in SQL and Me on 23 December 2013

SQL Server – Calculating elapsed time from DATETIME

Elapsed time can be calculated from DATETIME field by extracting number of hours/minutes and seconds. You can use below query to calculate elapsed time between two dates:

-- Vishal - http://SqlAndMe.com

DECLARE @startTime DATETIME
DECLARE @endTime DATETIME

SET @startTime = '2013-11-05 12:20:35'
SET @endTime = '2013-11-10 01:22:30'

SELECT	[DD:HH:MM:SS] =…

Read more

8 comments, 45 reads

Posted in SQL and Me on 23 December 2013

SQL Server – Kill all sessions using database

Before an existing database can be restored, there should be connections using the database in question. If the database is currently in use the RESTORE command fails with below error:

Msg 3101, Level 16, State 1, Line 2
Exclusive access could not be obtained because the database is in use.
Read more

3 comments, 39 reads

Posted in SQL and Me on 25 November 2013

SQL Server – Kill all sessions using database

Before an existing database can be restored, there should be connections using the database in question. If the database is currently in use the RESTORE command fails with below error:

Msg 3101, Level 16, State 1, Line 2
Exclusive access could not be obtained because the database is in use.
Read more

3 comments, 900 reads

Posted in SQL and Me on 25 November 2013

SQL Server – Custom sorting in ORDER BY clause

ORDER BY clause can be used to sort the results returned by SELECT statement in SQL Server. It orders the result set by specified column list. When used with character data type columns it sorts data in dictionary-order.

Sometimes, we need result set to be sorted in a custom order,… Read more

2 comments, 79 reads

Posted in SQL and Me on 18 November 2013

SQL Server – Custom sorting in ORDER BY clause

ORDER BY clause can be used to sort the results returned by SELECT statement in SQL Server. It orders the result set by specified column list. When used with character data type columns it sorts data in dictionary-order.

Sometimes, we need result set to be sorted in a custom order,… Read more

2 comments, 1,830 reads

Posted in SQL and Me on 18 November 2013

SQL Server – Script to get Service Account for all local instances

Earlier on my blog I posted on How to get SQL Server Service Account using T-SQL. That works on a single instance. If you multiple instances of SQL Server installed on a server you can use below script to get SQL Server and SQL Server Agent service account information… Read more

1 comments, 875 reads

Posted in SQL and Me on 26 August 2013

SQL Server – Script to get Service Account for all local instances

Earlier on my blog I posted on How to get SQL Server Service Account using T-SQL. That works on a single instance. If you multiple instances of SQL Server installed on a server you can use below script to get SQL Server and SQL Server Agent service account information… Read more

1 comments, 34 reads

Posted in SQL and Me on 26 August 2013

Older posts