How to find out SQL Version and Edition

There are many ways to find out SQL Server Version and Edition. I am sharing some of the most common ones.

 

1. SQL Commands

SELECT @@VERSION

Another Script:

SELECT SERVERPROPERTY (‘Edition’) as Edition,
SERVERPROPERTY(‘ProductLevel’) as SQLServicePackLevel,
SERVERPROPERTY(‘ProductVersion’) as SQLVersion

 

 

2. Using GUI – SSMS ->Object Explorer

Open SSMS and connect to SQL Instance, Right click sql instance and select properties.

here in the properties windows you can find out the SQL Version and Edition along with a lot of other useful details as well.

 

 

You can also find out the SQL Version (along with SP) when you connect NEW QUERY (in SSMS)

In the status bar below in New Query window (it show the SQL Version and Product Level)

 

 

SQL Server Version List

this list is taken from https://sqlserverbuilds.blogspot.ae/. This is one of the best places to refer for latest SQL releases and version details.

 

Hope this was helpful. !!!

 

 

 

 

Advertisements

How to find last start time of SQL Server

There are many ways to check when sql server was last started. Below are two of the options.

 

1. Using DMV

select sqlserver_start_time, * from sys.dm_os_sys_info

 

2. Using Server Dashboard Report

Connect to SQL Instance in Object explorer of SSMS. Right Click SQL Instance Select Reports -> Standard Reports -> Server Dashboard

 

 

Hope this was helpful !!!

 

Script to Check List of SQL Jobs, their Status and owner

Problem:   SQL Script to get list of SQL Jobs running under SQL Agent, their Status and Job Owner Details

 

Solution:   Below is the script.

 

SQL Script:

_______________________________________

USE msdb

SELECT j.[name] AS ‘JobName’,
Enabled = CASE
WHEN j.enabled = 0 THEN ‘No’
ELSE ‘Yes’
END,
l.[name] AS ‘OwnerName’
FROM msdb.dbo.sysjobs j
INNER JOIN master.dbo.syslogins l
ON j.owner_sid = l.sid
ORDER BY j.[name]

go

_______________________________________

 

ScreenShot:

 

jobdetails

SQL Server – Some commonly used DMV/DMFs by most of the DBAs

There are more than 150 DMV/DMFs spread across 20 some categories in 2012, and no one remember all these by heart.  Below are some commonly used DMV/DMFs by most the DBAs.

DMV /DMFs

— Execution related DMV and DMF

— Current Connections (User Processes only)
SELECT * FROM sys.dm_exec_connections

— Active Sessions
SELECT * FROM sys.dm_exec_sessions

— Currently executing requests
SELECT * FROM sys.dm_exec_requests

— Very Important: Query Statistics
SELECT * FROM sys.dm_exec_query_stats

— Cached Plans
SELECT * FROM sys.dm_exec_cached_plans

— Very Important: Query Optimizer details
SELECT * FROM sys.dm_exec_query_optimizer_info

— Very Important: Query Plan, This is DMF
SELECT TOP 1 * FROM sys.dm_exec_query_stats T1
CROSS APPLY sys.dm_exec_query_plan (T1.plan_handle )

— Very Important: SQL Statement, this is DMF
SELECT TOP 1 * FROM sys.dm_exec_query_stats T1
CROSS APPLY sys.dm_exec_SQL_text (T1.SQL_handle )

— Index related Dynamic Management Objects
— Index Usability
SELECT * FROM sys.dm_db_index_usage_stats

— Missing Indexes
SELECT * FROM sys.dm_db_missing_index_details

— Physical Stats, this is DMF, requires DBID, ObjectID, IndexID, PartitionID and Mode
SELECT * FROM sys.dm_db_index_physical_stats
(DB_ID(‘TESTDB‘), OBJECT_ID(‘EMPLOYEE‘), NULL, NULL , NULL) WHERE avg_fragmentation_in_percent >30

— SQL Server Operating system related Dynamic Management Objects

— Wait Stats
SELECT * FROM sys.dm_os_wait_stats

— Scheduler
SELECT * FROM sys.dm_os_schedulers

— Waiting/ Suspended Tasks
SELECT * FROM sys.dm_os_waiting_tasks WHERE Session_ID > 50

— Performance Counters
SELECT * FROM sys.dm_os_performance_counters

— Cluster Nodes Details
SELECT * FROM sys.dm_os_cluster_nodes

 

 

SQL Server – How to display line number in Query Editor- SSMS

Displaying line numbers in Query Editor is very useful, when you are working with large queries/module. As it is really annoying to find line number when a syntax error occurs [line numbers in Query Editor is not enabled].

How to enable or disable the display of line numbers in SSMS Query Editor

1. Open SQL Server Management Studio. Go to Tools > Options

1

2. In the Options dialog box on the left side panel expand the Text Editor option and expand Transact-SQL. Next select General as shown in the snippet below.

2.1

3. Tick the Line numbers checkbox and click OK.

2

 

4. Now, when a query window is opened Line Numbers will be displayed as below.

3

 

Hope this is helpful !!!!

How to backup Table in SQL

Taking backup of SQL Server table is possible in SQL Server. Below are some options to backup a table in SQL Server.

1. Generate Table Script with data
2. Make a copy of table using SELECT INTO
3. Export Data using SSIS to any destination

 

Method 1 : Generate Table Script with data

1 2 3 4 5 6

 

 

Method 2: Make a copy of table using SELECT INTO

Script:

 

7

SELECT * INTO DataBase.dbo.BackUpTable FROM SourceDataBase.dbo.SourceTable

 

Method 3: Export Data using SSIS to any destination [IMPORT / EXPORT Wizard]

The SQL Server Import and Export Wizard can copy data to and from any data source for which a managed .NET Framework data provider or a native OLE DB provider is available. The list of available providers includes the following data sources:

  • SQL Server
  • Flat files
  • Microsoft Office Access®
  • Microsoft Office Excel®

 

 

 

 

 

SQL Server- Installing SQL Server 2014

In this tutorial, I will show you step by step installation of SQL Server 2014 Evolution version (Default Instance).

Before you start, it’s highly recommended to check hardware and software requirements for Installing SQL Server 2014.

 

Step By Step (Installation)

1. Go to the Installation Setup (SQL Server 2014). Right click setup.exe and run as administrator.

1

2. Upon starting the installation, you will get this window. Go to the Installation tab on the left and then click “New SQL Server stand-alone installation or add features to an existing installation.

 

2

3. Enter the product key and click Next

 

 

3

4. Accept the license term in order to continue.

 

 

4

5. It checks your machine to make sure it meets the hardware and software requirements to install SQL Server. If you get any Errors in the results, do not move to the next step.

 

 

5

6. Choose the first option in order to install SQL Server, and Click Next.

 

6

7. Select which features to install. I have selected only limited features (Database engine, management tolls, client tools, integration services). Click Next to continue:

 

7

8. Select Default instance and click next.

 

 

8

9. In this step you can select the service accounts for the SQL Server actions. Each service in SQL Server represents a process or a set of processes to manage authentication of SQL Server operations with Windows. Each service can be configured to use its own service account. Its recommended to use domain account to run sql services in production. However, i have slected local account.  Click next to proceed.

 

9

10. Select collation and click next.

 

 

10

11. SQL Server can operate in one of two security (authentication) modes: (a) Windows Authentication mode which allowed a user to connect through an operating system user account. or (b) Mixed Mode which allowed users to connect to an instance of SQL Server using either Windows Authentication or SQL Server Authentication.

I have selected Mixed Mode and have spacified password for sa account.  I have also added my account as sql server adminstrator. Click next to proceed.

 

 

11

12. By default SQL Server uses the system operation disk  Thus it is highly recommended to use the best practice according to your specific system and usage. Separating the LOG files from the data files can improve performance significantly. The system database tempDB is used extensively by SQL Server. This database is rebuilt each time the server is restarted. It is best practice to separate data, transaction logs, and tempdb for environments where you can guarantee that separation.

As i have installing SQL on a virtual machine which has only one drive i.e C. I am going ahead with the default directory locations. Click next to proceed.

 

 

 

12

13. Review the summary of features and components for your SQL Server installation. To proceed, click Install

 

13 14 15 16

14. On the “Complete” page, you can view the Setup summary log by clicking the blue link provided on the bootom this page. To exit the SQL Server Installation Wizard, click Close. We have successfully installted SQL Server 2014.

 

 

 

17

Connecting to SQL Instance:

Go to the Start menu, and choose SQL Server 2014 Management Studio (SSMS), to connect to the newly created instance of SQL Server 2014

 

 

18

 

 

 

Hope this was helpful !!!

SQL Server – Uninstall /Remove SQL Server 2012 Failover Cluster Instance

Procedure to uninstall a SQL Server failover clustered instance

To update or remove a SQL Server failover cluster, you must be a local administrator with permission to login as a service on all nodes of the failover cluster.

 

To remove a node from an existing SQL Server failover cluster

  1. Insert the SQL Server installation media. From the root folder, double-click setup.exe. To install from a network share, navigate to the root folder on the share, and then double-click Setup.exe.
  2. The Installation Wizard launches the SQL Server Installation Center. To remove a node to an existing failover cluster instance, click Maintenance in the left-hand pane, and then select Remove node from a SQL Server failover cluster.
  3. The System Configuration Checker will run a discovery operation on your computer. To continue, Click OK. .
  4. After you click install on the Setup Support Files page, the System Configuration Checker verifies the system state of your computer before Setup continues. After the check is complete, click Next to continue.
  5. On the Cluster Node Configuration page, use the drop-down box to specify the name of the SQL Server failover cluster instance to be modified during this Setup operation. The node to be removed is listed in the Name of this node field.
  6. The Ready to Remove Node page displays a tree view of options that were specified during Setup. To continue, click Remove.
  7. During the remove operation, the Remove Node Progress page provides status.
  8. The Complete page provides a link to the summary log file for the remove node operation and other important notes. To complete the SQL Server remove node, click Close.

 

Screenshots: 

1 2 3 4 5 6 7

 

 

Repeat above steps on all nodes used for the SQL Server clustered instance. Make sure you uninstall the active node last.

Note:    Remove Passive Nodes First and Active node Last.

SQL Server – How to attach database without LDF file

There can be a situation where you don’t have full database backup and you have corrupted your ldf file due to power shutdown (or some one intentionally deleted the ldf file). And you are left with only the data file (i.e mdf file).  You can still attach your mdf file with database and recover it.

Below is an example of how, you can attach a database without ldf file.

Database Name : Northwind

Data File:              C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\northwnd.mdf

Log File:                Not Available

 

Using SSMS : Attaching database without LDF File

  • Connect to the SQL server instance using SSMS
  • From the Object Explorer, right click the Databases node and a drop-down menu will be appeared.
  • Now click on the Attach tab.

 

2

 

 

  • Click on the Add button from appeared dialog box.

3

 

 

  • Now a Locate Database File, select it and click ok. Now you will see your mdf file is selected but SQL server is unable to select your transaction log file because transaction log file was deleted.

 

 

4

 

  • Now if you click OK, it will fail with the operating system error ( unable to open the physical file).

 

 

5

 

 

6

 

  • To attach .mdf file without transaction log file; select the log file and click on the remove button to remove it.
  • Now click on the OK button to attach the database file. SQL server will create a transaction log file for you while attaching the database.

 

7

 

 

 

9

 

 

Hope this was helpful !!!

SQL Server – Different ways to check recovery model

Recovery Model (SQL Server)

SQL Server backup and restore operations occur within the context of the recovery model of the database. Recovery models are designed to control transaction log maintenance. A recovery model is a database property that controls how transactions are logged, whether the transaction log requires (and allows) backing up, and what kinds of restore operations are available. Three recovery models exist: simple, full, and bulk-logged. Typically, a database uses the full recovery model or simple recovery model. A database can be switched to another recovery model at any time.

 

There are many ways to check recovery model of a database in SQL Server.  Below are few commonly used examples.

1. Using Management Studio

Right click on Database in Object Explorer > go to Properties dialog box > Options page >Recovery model

2

 

2. Using catalog view [sys.databases]

SELECT [DatabaseName]=name,
[RecoveryModel]=recovery_model_desc
FROM sys.databases
GO

3

3. Using Metadata function – DATABASEPROPERTYEX()

SELECT ‘AdventureWorks2012’ AS [Database Name],
DATABASEPROPERTYEX(‘AdventureWorks2012’, ‘RECOVERY’)
AS [Recovery Model]
GO

4

 

4. Using Object Explorer Details

Click on the Database Node in Object Explorer. In Object Explorer Details, you can find Recovery Model for all databases.

1

 

 

Hope this was helpful!!!