Home » Posts tagged 'SQL Server 2014' (Page 2)

Tag Archives: SQL Server 2014

SQL Server 2005 Onwards – Mirrored Backup || Cool Feature

SQL Server 2005 onwards includes the mirroring of backup media sets to provide redundancy of your critical database backups. Mirroring a media set increases backup reliability by reducing the impact of backup-device malfunctions. These malfunctions are very serious because backups are the last line of defense against data loss. SQL Server 2005 Standard Edition supports only a single backup copy during your backup operations. Depending on your requirements, SQL Server Enterprise allows you to create up to four mirrored media sets.

Benefits
Mirrored backup media sets improve availability by minimizing downtime during restore operations. A damaged backup could result in a longer restore time, or a restore failure. As databases grow, the probability increases that the failure of a backup device or media will make a backup unrestorable. Restoring a database is time sensitive, and mirrored backup media sets give you added protection to get your application fully functional more quickly.

In SQL Server 2005 and later versions, there is a Mirror command that makes a copy of the database backup to different locations while taking the original backup. The maximum limit of additional locations that can be specified with MIRROR clause is 3.

Mirrored backup can be taken in local computer system as well as in a local network. Let us now see two examples of mirror backup.

Example 1. Single File Backup to Multiple Locations using Mirror

BACKUP DATABASE AdventureWorks2012

TO DISK = ‘d:AdventureWorksBackup1.bak’

MIRROR TO DISK = ‘d:AdventureWorksBackupCopy.bak’

with format

If this command is being run for the first time, it is mandatory to use the WITH FORMAT clause; but for sub sequential runs it is not required. WITH FORMAT reinitializes the backup.

Example 2. Multiple File Backup to Multiple Locations using Mirror

BACKUP DATABASE AdventureWorks2012

TO DISK = ‘d:AdventureWorksBackup1.bak’,

disk = ‘d:AdventureWorksBackup2.bak’

MIRROR TO DISK = ‘d:AdventureWorksBackupCopy.bak’,

DISK = ‘d:AdventureWorksBackupCopy1.bak’

with format

Example 3. Only 4 Mirror are allowed (1 Backup file + 3 Mirror files)

Example 4. Different number of backup file & Mirror files – Error Occur

 

 

 

 

If you liked this post, do like on Facebook at http://www.facebook.com/mssqlfun

Reference : Rohit Garg (http://mssqlfun.com/)

How to find current/particular transaction level?

There is 2 ways of finding current / particular transaction level :-

1)

SELECT CASE transaction_isolation_level

WHEN 0 THEN ‘Unspecified’

WHEN 1 THEN ‘ReadUncomitted’

WHEN 2 THEN ‘Readcomitted’

WHEN 3 THEN ‘Repeatable’

WHEN 4 THEN ‘Serializable’

WHEN 5 THEN ‘Snapshot’ END AS TRANSACTION_ISOLATION_LEVEL

FROM sys.dm_exec_sessions

where session_id = @@SPID

2)

DECLARE @UserOptions TABLE(SetOption varchar(100), Value varchar(100))

DECLARE @IsolationLevel varchar(100)

INSERT @UserOptions

EXEC(‘DBCC USEROPTIONS WITH NO_INFOMSGS’)

SELECT @IsolationLevel = Value

FROM @UserOptions

WHERE SetOption = ‘isolation level’

 

If you liked this post, do like on Facebook at http://www.facebook.com/mssqlfun

Reference : Rohit Garg (http://mssqlfun.com/)

How to Insert datetime with different Timezones

In SQL Server 2008, Microsoft has introduced a number of new date and time data types. One of these is the datetimeoffset data type. This data type includes an offset from UTC time as well as the datetime value and ensures that the datetime can be retrieved in UTC or a particular timezone based on this offset. There are also new functions to allow for conversions between different time zones using the new function SWITCHOFFSET().

select

converT(datetime,SWITCHOFFSET(converT(datetimeoffset,getdate()),’+05:30′)) Date_India,

converT(datetime,SWITCHOFFSET(converT(datetimeoffset,getdate()),’+03:30′)) Date_Iran

 

If you liked this post, do like on Facebook at http://www.facebook.com/mssqlfun

Reference : Rohit Garg (http://mssqlfun.com/)

Query Execution Plan from XML to Graphical View

Convert Your SQL Server Query Execution Plan from XML to Graphical View

1) We can get queries execution plan from below query

SELECT

QS.*, CP.*

FROM SYS.DM_EXEC_QUERY_STATS AS QS

CROSS APPLY SYS.DM_EXEC_SQL_TEXT(SQL_HANDLE)AS ST

CROSS APPLY SYS.DM_EXEC_QUERY_PLAN(PLAN_HANDLE) AS CP

2) Column query_plan is having execution plan in XML form

3) When we click hyperlink in query_plan column, in SQL 2005,2008 & 2008 R2 it open as XML but in SQL 2012 it converted to graphical view

aaa

 

4) To convert XML to graphical view, save XML file with extension .sqlplan & open it with SSMS

5) Now plan will show in graphical view

 

If you liked this post, do like on Facebook at http://www.facebook.com/mssqlfun

Reference : Rohit Garg (http://mssqlfun.com/)

%d bloggers like this: