SQLRelease http://www.sqlrelease.com Machine Learning, Data Science, Python, SQL Server, Big Data, BI, and DWH Tue, 21 Aug 2018 04:54:27 +0000 en-US hourly 1 Tidy Data in Python – First Step in Data Science and Machine Learning http://www.sqlrelease.com/tidy-data-in-python-first-step-in-data-science-and-machine-learning http://www.sqlrelease.com/tidy-data-in-python-first-step-in-data-science-and-machine-learning#respond Mon, 20 Aug 2018 06:39:18 +0000 http://www.sqlrelease.com/?p=1502 Most of the Data Science / Machine Learning projects follow the Pareto principle where we spend almost 80% of the time in data preparation and remaining 20% in choosing and training the appropriate ML model. Mostly, the datasets we get to create Machine Learning models are messy datasets and cannot be fitted into the model directly. We need to perform some data cleaning steps in order to get a dataset which then can be fitted into the model. We need to make sure that the data we are inputting into the model is a tidy data. Indeed, it is the first step in a Machine Learning / Data Science project. We may need to repeat the data cleaning process many times as we face new challenges and problems while cleaning the data. Data cleaning is one of the most important and time taking process a Data Scientist performs before … More

The post Tidy Data in Python – First Step in Data Science and Machine Learning appeared first on SQLRelease.

http://www.sqlrelease.com/tidy-data-in-python-first-step-in-data-science-and-machine-learning/feed 0
Conditional group by in SQL Server http://www.sqlrelease.com/conditional-group-by-in-sql-server http://www.sqlrelease.com/conditional-group-by-in-sql-server#respond Tue, 31 Jul 2018 10:54:08 +0000 http://www.sqlrelease.com/?p=1495 In this post, we are going to learn how we can apply a conditional GROUP BY clause on a column, based on the values of another column. Assume that we have a table named tbl_EmpSaleDetail which contains the sales records for each employee. Let’s have a look at the table data.

In the above table, we have these columns:

EmpName – Stores the name of the employee

SaleDate – Date of sale

SaleAmount – Amount of the sale

IsActive – Indicates whether the employee is active or not.

Now, we need this output.

In this output, we can see that all the data of inactive employees have been aggregated to a single row labeled as “–Inactive Employees Sales–” (Highlighted in red). However, the sum of the sales of the active employees are aggregated individually. Before writing the conditional group by query, lets create the sample table … More

The post Conditional group by in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/conditional-group-by-in-sql-server/feed 0
Python use case – Import data from excel to sql server table – SQL Server 2017 http://www.sqlrelease.com/python-use-case-import-data-from-excel-to-sql-server-table-sql-server-2017 http://www.sqlrelease.com/python-use-case-import-data-from-excel-to-sql-server-table-sql-server-2017#respond Sat, 30 Jun 2018 13:23:37 +0000 http://www.sqlrelease.com/?p=1482 If we need to import data from an excel file into SQL Server, we can use these methods:

  1. SQL Server Import Export Wizard
  2. Create an SSIS package to read excel file and load data into a SQL Server table
  3. Use T-SQL OPENROWSET query
  4. Use the read_excel method of Python’s pandas library (Only available in SQL Server 2017 onwards)

In this post “Python use case – Import data from excel to sql server table – SQL Server 2017”, we are going to learn that how we can use the power of Python in SQL Server 2017 to read a given excel file in a SQL table directly. With the integration of Python in SQL Server 2017, we can use the pandas read_excel method to read a given excel file with lots of customizations in SQL Server.

Assume that we have an excel file named EmployeeList.xlsx as this. Click here to More

The post Python use case – Import data from excel to sql server table – SQL Server 2017 appeared first on SQLRelease.

http://www.sqlrelease.com/python-use-case-import-data-from-excel-to-sql-server-table-sql-server-2017/feed 0
Python use case – Import zipped file without unzipping it in SSIS and SQL Server – SQL Server 2017 http://www.sqlrelease.com/python-use-case-import-zipped-file-without-unzipping-it-in-ssis-and-sql-server-sql-server-2017 http://www.sqlrelease.com/python-use-case-import-zipped-file-without-unzipping-it-in-ssis-and-sql-server-sql-server-2017#respond Thu, 31 May 2018 07:41:41 +0000 http://www.sqlrelease.com/?p=1459 Import zipped CSV file without unzipping it in SSIS using SQL Server 2017

SQL Server Integration Services (SSIS) is one of the most popular ETL tools. It has many built-in components which can be used in order to automate the enterprise ETL(Extract, Transform, and Load). Also, if we need a customized component which is not available in SSIS, we can simply create it by writing our own piece of code in C# using Script Task or Script Component.

In this post, we are going to explore that how we can read and load a zipped CSV file in SQL Server without unzipping it using SSIS along with SQL Server 2017. Reading a zipped file directly (without unzipping it) will save some time required in order to write the text file on the physical disk and then reading it from there. As of now, we don’t have any built-in component in … More

The post Python use case – Import zipped file without unzipping it in SSIS and SQL Server – SQL Server 2017 appeared first on SQLRelease.

http://www.sqlrelease.com/python-use-case-import-zipped-file-without-unzipping-it-in-ssis-and-sql-server-sql-server-2017/feed 0
Find and Delete all duplicate rows but keep one http://www.sqlrelease.com/find-and-delete-all-duplicate-rows-but-keep-one http://www.sqlrelease.com/find-and-delete-all-duplicate-rows-but-keep-one#respond Mon, 30 Apr 2018 16:38:15 +0000 http://www.sqlrelease.com/?p=1461 In this post “Find and Delete all duplicate rows but keep one”, we are going to discuss that how we can find and delete all the duplicate rows of a table except one row. Assume that we have a table named tbl_sample which has four columns – EmpId, EmpName, Age, and City. This table has some duplicate data (in all the four columns) which needs to be deleted except the original one row. To demonstrate this, let’s create the dummy table with some sample data.

Here is the code to create the dummy table with sample data:

Let’s have a look at the table data now.

In above table, we can see that we have multiple duplicate rows for EmpId 1, 2, 3 and 4. To find the duplicate records from the above table, we can use this query. This query will output all the duplicate rows from the … More

The post Find and Delete all duplicate rows but keep one appeared first on SQLRelease.

http://www.sqlrelease.com/find-and-delete-all-duplicate-rows-but-keep-one/feed 0
Import CSV file into SQL Server using T-SQL query http://www.sqlrelease.com/import-csv-file-into-sql-server-using-t-sql-query http://www.sqlrelease.com/import-csv-file-into-sql-server-using-t-sql-query#comments Sat, 31 Mar 2018 08:44:25 +0000 http://www.sqlrelease.com/?p=1441 Sometimes, we need to read an external CSV file using T-SQL query in SQL Server. Due to some functional limitations, we cannot use the import-export wizard functionality in such kinds of scenarios as we need the result set in the middle of the execution of the other queries. There, we can use the BULK INSERT SQL command which helps us to import a data file into SQL Server table directly.

Let’s have a look at the sample CSV file which we want to import into a SQL table. The CSV file is this.

To download the sample CSV file, click here. The above CSV file uses comma as a column delimiter and contains 6 columns which are:

PersonID – Stores the Id of the person.

FullName – Stores the full name of the person.

PreferredName – Stores the preferred name of the person.

SearchName – Stores the search name … More

The post Import CSV file into SQL Server using T-SQL query appeared first on SQLRelease.

http://www.sqlrelease.com/import-csv-file-into-sql-server-using-t-sql-query/feed 3
Python use case – Convert rows into comma separated values in a column – SQL Server 2017 http://www.sqlrelease.com/python-use-case-convert-rows-into-comma-separated-values-in-a-column-sql-server-2017 http://www.sqlrelease.com/python-use-case-convert-rows-into-comma-separated-values-in-a-column-sql-server-2017#respond Tue, 27 Feb 2018 09:03:39 +0000 http://www.sqlrelease.com/?p=1419 In this post, we are going to learn how we can leverage python in SQL server to generate comma separated values.

If we want to combine all values of a single column it is fairly easy as we can use COALESCE function to do that. Here is a reference to the already existing post. But have you ever thought what would happen if we needed a comma separated value in a column along with other columns? In that scenario, this approach would not work.

We can get comma separated values in a column along with other columns using FOR XML PATH  query wrapped inside a sub-query, but there also we would need to take care of HTML encoded characters like < and >.

Now, with python’s integration with SQL Server 2017, it can be achieved very easily and efficiently as we do not have to rely on subqueries and … More

The post Python use case – Convert rows into comma separated values in a column – SQL Server 2017 appeared first on SQLRelease.

http://www.sqlrelease.com/python-use-case-convert-rows-into-comma-separated-values-in-a-column-sql-server-2017/feed 0
Python use case – Dynamic UNPIVOT using pandas – SQL Server 2017 http://www.sqlrelease.com/python-use-case-dynamic-unpivot-using-pandas-sql-server-2017 http://www.sqlrelease.com/python-use-case-dynamic-unpivot-using-pandas-sql-server-2017#comments Mon, 26 Feb 2018 07:56:01 +0000 http://www.sqlrelease.com/?p=1388 In this post, we are going to learn how we can leverage the power of Python’s pandas module in SQL Server 2017. pandas is an open source Python library providing data frame as data structure similar to the SQL table with the vectorized operation support for high performance. To know more about pandas, you can click here.

Let’s discuss the problem we face while using the SQL UNPIVOT clause especially when we have a large number of columns. We can use UNPIVOT clause in SQL Server to convert the columns as row values and normalize the output result set. To use the UNPIVOT command, we need to specify each column name as a fixed value while writing the T-SQL query. However, this becomes annoying if we need to specify a large number of columns in the UNPIVOT clause. Also, if the column names are not fixed (dynamic in nature), … More

The post Python use case – Dynamic UNPIVOT using pandas – SQL Server 2017 appeared first on SQLRelease.

http://www.sqlrelease.com/python-use-case-dynamic-unpivot-using-pandas-sql-server-2017/feed 1
Handling special characters in Hive (using encoding properties) http://www.sqlrelease.com/handling-special-characters-in-hive-using-encoding-properties http://www.sqlrelease.com/handling-special-characters-in-hive-using-encoding-properties#comments Mon, 08 Jan 2018 08:35:00 +0000 http://www.sqlrelease.com/?p=1383 In case we are reading a text file in a Hive table which contains non-English characters and we are not using the appropriate text encoding, these non-English characters might be loaded as junk symbols (like boxes – �). To get these characters in their original form, we need to use the correct character encoding. In this post “Handling special characters in Hive (using encoding properties)“, we are going to learn that how we can read special characters in Hive using encoding properties available with TBLPROPERTIES clause.

To demonstrate it, we will be using a dummy text file which is in ANSI text encoding format and contains Spanish characters. Also, we will be using Microsoft Azure cloud platform to instantiate an on-demand HDInsight cluster that makes it easy to write Hive queries. We will upload the dummy text file to an Azure Data Lake Storage and then we will … More

The post Handling special characters in Hive (using encoding properties) appeared first on SQLRelease.

http://www.sqlrelease.com/handling-special-characters-in-hive-using-encoding-properties/feed 1
Skip header and footer rows in Hive http://www.sqlrelease.com/skip-header-and-footer-rows-in-hive http://www.sqlrelease.com/skip-header-and-footer-rows-in-hive#comments Mon, 11 Dec 2017 10:09:27 +0000 http://www.sqlrelease.com/?p=1372 In this post “Skip header and footer rows in Hive“, we are going to learn that how we can ignore few header and footer records in Hive without loading or reading these records in another table or in a view temporarily. If you want to read more about Hive, visit my post “Preserve Hive metastore in Azure HDInsight” which explains Hive QL in detail.

Skip header and footer records in Hive

We can ignore N number of rows from top and bottom from a text file without loading that file in Hive using TBLPROPERTIES clause. The TBLPROPERTIES clause provides various features which can be set as per our need. It can be used in this scenario to handle the files which are being generated with additional header and footer records. Let’s have a look at the below sample file:

Now assume that we are dealing with … More

The post Skip header and footer rows in Hive appeared first on SQLRelease.

http://www.sqlrelease.com/skip-header-and-footer-rows-in-hive/feed 1
Preserve Hive metastore in Azure HDInsight http://www.sqlrelease.com/preserve-hive-metastore-in-azure-hdinsight http://www.sqlrelease.com/preserve-hive-metastore-in-azure-hdinsight#comments Mon, 27 Nov 2017 06:15:30 +0000 http://www.sqlrelease.com/?p=1344 In this blog “Preserve Hive metastore in Azure HDInsight“, we are going to learn how we can preserve the hive metadata while working with the Azure HDInsight services. Microsoft Azure HDInsight is an on-demand managed Open source Big Data analytics service for the enterprises. We can provision clusters as per the demand in few minutes, perform the computations, and then we can shut it down to avoid charges. We pay as per the usage only. You can visit this link to know more about Azure HDInsight.

What is Hive?

Apache Hive is a SQL like Big Data query language which is used as an abstraction for the map reduce jobs. The Hive query seamlessly converts into an equivalent map reduce job without the need to write low-level code. This increases the productivity of a developer to a great extent. If you want to read more about Hive … More

The post Preserve Hive metastore in Azure HDInsight appeared first on SQLRelease.

http://www.sqlrelease.com/preserve-hive-metastore-in-azure-hdinsight/feed 1
Connecting Python 3 to SQL Server 2017 using pyodbc http://www.sqlrelease.com/connecting-python-3-to-sql-server-2017-using-pyodbc http://www.sqlrelease.com/connecting-python-3-to-sql-server-2017-using-pyodbc#comments Thu, 23 Nov 2017 07:17:23 +0000 http://www.sqlrelease.com/?p=1320 In this post “Connecting Python 3 to SQL Server 2017 using pyodbc”, we are going to learn that how we can connect Python 3 to SQL Server 2017 to execute SQL queries. We can change the settings accordingly to connect to other versions of SQL Server also. If you are interested to know more about Python and why you should learn it, visit our post “Why Python and how to use it in SQL Server 2017“.

What is pyodbc?

pyodbc is an open source DB API 2 Python module. It provides a convenient interface to connect a database which accepts an ODBC connection. In order to use pyodbc module, firstly, we need to install it. Click here for more information on pyodbc.

pip install pyodbc module

We can use pip install command to install the pyodbc module in Python 3 on a Windows machine. Before executing the … More

The post Connecting Python 3 to SQL Server 2017 using pyodbc appeared first on SQLRelease.

http://www.sqlrelease.com/connecting-python-3-to-sql-server-2017-using-pyodbc/feed 3
Free C# Entity Generator or C# Class Generator http://www.sqlrelease.com/free-c-entity-generator-or-c-class-generator http://www.sqlrelease.com/free-c-entity-generator-or-c-class-generator#respond Sat, 18 Nov 2017 10:36:27 +0000 http://www.sqlrelease.com/?p=1113 C# Entity Generator or Class Generator Tool

A few years back, I created a tool “C# Entity Generator”. Though it was created for an older version of visual studio, still it can be useful. I am sharing this tool here so that anyone can download and use it for free. This tool does not require any installation and is a copy paste utility.

C# Entity Generator is a tool which can be used to generate C# Entity Layer classes without writing a single line of code. If we are using three-tier architecture in our applications and need to create entities frequently to map the output of the relational queries, this tool can be very useful. It increases the developer’s productivity especially if the entity contains a large set of properties. Only once would we need to define the data types, their prefixes as per the naming convention guidelines, and their … More

The post Free C# Entity Generator or C# Class Generator appeared first on SQLRelease.

http://www.sqlrelease.com/free-c-entity-generator-or-c-class-generator/feed 0
Python use case – Get employees for given skill set – SQL Server 2017 http://www.sqlrelease.com/python-use-case-get-employees-given-skill-set-sql-server-2017 http://www.sqlrelease.com/python-use-case-get-employees-given-skill-set-sql-server-2017#respond Tue, 31 Oct 2017 13:53:18 +0000 http://www.sqlrelease.com/?p=1290 In the previous blog post “Python use case – Map unequal comma separated values from two columns – SQL Server 2017“, we demonstrated a use case example of Python in SQL Server 2017. Now, in this post, “Python use case – Get employees for given skill set – SQL Server 2017”, we are going to explore another use case example of Python in SQL Server 2017.

As Microsoft has integrated Python in SQL Server 2017 for advanced data analytics and machine learning purpose, it can also be used to ease the complex data transformation and analysis which might be tedious and a bit complex while doing the same using T-SQL.

Let’s create the required table with the sample data to demonstrate the use case example.

Python use case – Get employees for given skill set

Assume that, we have a table employee master named as tbl_EmpMaster which has … More

The post Python use case – Get employees for given skill set – SQL Server 2017 appeared first on SQLRelease.

http://www.sqlrelease.com/python-use-case-get-employees-given-skill-set-sql-server-2017/feed 0
Python use case – Map unequal comma separated values from two columns – SQL Server 2017 http://www.sqlrelease.com/python-use-case-map-unequal-comma-separated-values-from-two-columns-sql-server-2017 http://www.sqlrelease.com/python-use-case-map-unequal-comma-separated-values-from-two-columns-sql-server-2017#comments Sat, 30 Sep 2017 15:06:08 +0000 http://www.sqlrelease.com/?p=1266 We know that Microsoft has integrated Python in SQL Server 2017 to enable rich data analytics capabilities within the database itself. Python is one of the most powerful languages which provides lots of built-in libraries for advanced data analytics and transformations. We can use Python for almost everything from website development to robotics and Data Science. In SQL Server 2017, Python can be used primarily for Machine learning purposes but it is not limited to that only. We can also use Python for complex data transformations and analysis which might be a bit tedious and complex while doing the same using T-SQL in SQL Server.

In this post, we will be exploring an use case example of Python for data transformation in SQL Server 2017. If you want to read more about Python and how to use it in SQL Server, you can visit my previous blog post “Why More

The post Python use case – Map unequal comma separated values from two columns – SQL Server 2017 appeared first on SQLRelease.

http://www.sqlrelease.com/python-use-case-map-unequal-comma-separated-values-from-two-columns-sql-server-2017/feed 4
Why Python and how to use it in SQL Server 2017 http://www.sqlrelease.com/why-python-and-how-to-use-it-in-sql-server-2017 http://www.sqlrelease.com/why-python-and-how-to-use-it-in-sql-server-2017#comments Thu, 31 Aug 2017 09:54:13 +0000 http://www.sqlrelease.com/?p=1254 Microsoft has integrated Python in SQL Server 2017 which can be used for in-database analysis purpose. In this post, we are going to explore “Why Python and how to use it in SQL Server 2017”, and then we will explore that how we can use it in SQL Server 2017.

Why Python

Python is a general purpose object oriented programming language which can be used to develop applications for a variety of domains. We can use Python for almost everything from desktop and website development, gaming, robotics, scientific and numeric computing to spacecraft control and much more. Python is a high-level programming language which is an interpreted language (execute line by line) instead of compiled language. The Python has gained popularity because of its user friendliness. The developers fall in love with Python because it is easy to learn, but still very powerful. The technology giants like Google, YouTube, Dropbox, … More

The post Why Python and how to use it in SQL Server 2017 appeared first on SQLRelease.

http://www.sqlrelease.com/why-python-and-how-to-use-it-in-sql-server-2017/feed 2
SQL Server 2017 New Features http://www.sqlrelease.com/sql-server-2017-new-features http://www.sqlrelease.com/sql-server-2017-new-features#comments Sun, 30 Jul 2017 14:44:49 +0000 http://www.sqlrelease.com/?p=1247 Microsoft has launched the most recent SQL Server 2017 release candidate (RC1, July 2017). It can be downloaded from this link. SQL Server 2017 will run on both Windows as well as on Linux OS. It also supports macOS via Docker too. In this post, we will discuss the new features of SQL Server 2017.

SQL Server 2017 New Features (SQL Server vNext)

Though the SQL Server 2017 has many new features, in this post, we are going to highlight the features which can be mostly used by SQL Server Developers.

1. SQL Server Machine Learning Services – R and Python

SQL Server 2016 integrated the R programming which can be run within the database server and can be embedded into T-SQL script too. Now, in SQL Server 2017, we can execute the Python script within the database server itself. Both, R and Python are most popular programming language … More

The post SQL Server 2017 New Features appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-2017-new-features/feed 1
Work offline with SSIS package http://www.sqlrelease.com/work-offline-ssis-package http://www.sqlrelease.com/work-offline-ssis-package#respond Fri, 30 Jun 2017 13:12:43 +0000 http://www.sqlrelease.com/?p=1236 Sometimes it happens that we need to open an SSIS package which contains connections which are not accessible or not allowed to be accessed due to some security reasons. In this post “Work offline with SSIS package”, we are going to learn that how we can open, read, and modify the components of an SSIS package when its connection managers are not able to connect to the underlying data source. This feature can be highly useful when it comes that there is a developer who is not authorized to access the underlying data source being used in the package but he needs to read some column mappings information from the source and destinations being used in the package.

Whenever we open an SSIS package in Visual Studio designer, the designer tries to connect to the data sources being used by the package to verify the metadata. And if it fails … More

The post Work offline with SSIS package appeared first on SQLRelease.

http://www.sqlrelease.com/work-offline-ssis-package/feed 0
Specific row at the top then sort the rest result set in SQL Server http://www.sqlrelease.com/specific-row-at-the-top-then-sort-the-rest-result-set-in-sql-server http://www.sqlrelease.com/specific-row-at-the-top-then-sort-the-rest-result-set-in-sql-server#comments Wed, 31 May 2017 15:09:05 +0000 http://www.sqlrelease.com/?p=1225 In this post, “Specific row at the top then sort the rest result set in SQL Server“, we are going to learn that how we can order a result set in a customized way which cannot be achieved using ORDER by Clause in a simple way.

To demonstrate this, let’s create a sample table named as “tbl_Department” and insert some dummy rows in it. Below is the code to create the sample table:

Now, add some sample rows into the table:

Let’s have a look at the table data now:

From this table, we need to extract all rows and columns by ordering them on DeptName column. However, we need to keep “Not Assigned” department name value at the top of the list and then the rest of the department name values should be ordered alphabetically in ascending order. Have a look at the desired output:… More

The post Specific row at the top then sort the rest result set in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/specific-row-at-the-top-then-sort-the-rest-result-set-in-sql-server/feed 2
Use NEWID() inside function in SQL Server http://www.sqlrelease.com/use-newid-inside-function-in-sql-server http://www.sqlrelease.com/use-newid-inside-function-in-sql-server#respond Sun, 30 Apr 2017 07:20:58 +0000 http://www.sqlrelease.com/?p=1216 In SQL Server, if we use the NEWID() function inside an user-defined function, it throws an error as “Invalid use of side-effecting or time-dependent operator in ‘newid()’ within a function.

For any reason, if we need to use the NEWID() function inside an user-defined function, we need to do some work around. In this post, we will discuss few tips which can be used to deal with such kind of scenarios.

To demonstrate this problem, first, let’s create a user defined function which uses NEWID() function inside. Though in production environment we might be using more complex logic with the NEWID value, but in this demo, to keep it simple, we will be using the LOWER() function which converts the given value to the lower case.

When we will try to create this function we will get below error message:

How to use NEWID() in a function

As … More

The post Use NEWID() inside function in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/use-newid-inside-function-in-sql-server/feed 0
Extract the first number from an alphanumeric string in sql server http://www.sqlrelease.com/extract-the-first-number-from-an-alphanumeric-string-in-sql-server http://www.sqlrelease.com/extract-the-first-number-from-an-alphanumeric-string-in-sql-server#comments Mon, 27 Mar 2017 13:45:01 +0000 http://www.sqlrelease.com/?p=1204 In this post, we are going to learn how to extract the first numeric value from an alphanumeric string in SQL Server. To demonstrate this, we will create a dummy table and then we will insert some dummy rows into that table. Finally, we will use a SELECT statement to extract the first numeric value from the given alphanumeric string for each row of the table.

Let’s create the dummy table as below:

Now, let’s insert some alphanumeric values in this table as below:

We have below sample records in the testTable:

Now, to extract the first numeric value for each row of the table, we can use a SELECT query as below:

Below is the output:

Understanding the query

To extract the first number from the given alphanumeric string, we are using a SUBSTRING function. In the substring function, we are extracting a substring from the given string starting More

The post Extract the first number from an alphanumeric string in sql server appeared first on SQLRelease.

http://www.sqlrelease.com/extract-the-first-number-from-an-alphanumeric-string-in-sql-server/feed 4
Checkpoints with containers in SSIS http://www.sqlrelease.com/checkpoints-containers-ssis http://www.sqlrelease.com/checkpoints-containers-ssis#respond Mon, 20 Feb 2017 06:01:37 +0000 http://www.sqlrelease.com/?p=1185 In the previous post “Using checkpoints in an SSIS package“, we discussed how to configure an SSIS package in order to enable the checkpoints. Now, In this post “Checkpoints with containers in SSIS“, we are going learn how to configure a package to restart from the first task of the container in which it fails instead of the beginning of the package.

Most of the time, in an SSIS package, containers are used to group a set of tasks in a single unit of work and if the package gets failed, we need to restart the package from the beginning of the container instead of restarting it from the beginning of the package. Let’s create a dummy package and demonstrate it.

Using checkpoints with containers in an SSIS package – Demo

In this demonstration, we are going to use sequence container to group multiple tasks in … More

The post Checkpoints with containers in SSIS appeared first on SQLRelease.

http://www.sqlrelease.com/checkpoints-containers-ssis/feed 0
Using checkpoints in an SSIS package http://www.sqlrelease.com/using-checkpoints-in-an-ssis-package http://www.sqlrelease.com/using-checkpoints-in-an-ssis-package#comments Mon, 09 Jan 2017 14:06:16 +0000 http://www.sqlrelease.com/?p=1172 Checkpoints in SSIS

In this post “Using checkpoints in an SSIS package”, we are going to learn how to configure checkpoints in an SSIS package.

SQL Server integration services use checkpoints in order to avoid the re-execution of an SSIS package from the beginning in case the package fails during execution. Checkpoints can be extremely useful in case the task prior to the point of failure takes a long time to execute. For example, if we are dealing with an SSIS package which is loading a huge amount of data from an OLTP server (highly transactional) to a destination server and is taking a long time to accomplish the data loading operation, and if the package gets failed after the data loading operation (at any other task being executed later on), we would not like to restart the package from the beginning which will take a long time to reload … More

The post Using checkpoints in an SSIS package appeared first on SQLRelease.

http://www.sqlrelease.com/using-checkpoints-in-an-ssis-package/feed 2
Get error column name in Data Flow Task in SSIS http://www.sqlrelease.com/get-error-column-name-in-data-flow-task-in-ssis http://www.sqlrelease.com/get-error-column-name-in-data-flow-task-in-ssis#respond Sat, 31 Dec 2016 15:13:45 +0000 http://www.sqlrelease.com/?p=1152 How to get error column name and error description in Data Flow Task in SSIS

During execution of an SSIS package, when a bad row comes in the data flow task, the task gets failed. However, most of the components (source, transformation, and destination) in the data flow task exposes an error output path which can be configured to redirect these invalid records to the error output path and then we can log these redirected bad records using a destination component. Once all these bad records get logged, we can investigate the root cause of the errors, fix them, and then these bad rows can be reintroduced again.

The error output path in the data flow task contains two four byte int columns, ErrorColumn and ErrorCode, which represent the lineage id of the error column and the error code respectively. The values in both these columns are numeric which … More

The post Get error column name in Data Flow Task in SSIS appeared first on SQLRelease.

http://www.sqlrelease.com/get-error-column-name-in-data-flow-task-in-ssis/feed 0
Covering index and its usage http://www.sqlrelease.com/covering-index-and-its-usage http://www.sqlrelease.com/covering-index-and-its-usage#respond Wed, 30 Nov 2016 14:03:37 +0000 http://www.sqlrelease.com/?p=1137 What is a covering index

A covering index is an index which satisfies all the columns being used in a query without performing a further lookup either to the clustered index or to the base table. It contains all the columns whether they are used in SELECT, JOIN, WHERE, GROUP BY, or ORDER BY clause of the query. Covering index works like a pseudo-clustered index for the query. It improves the performance of the query by adding non-key columns in the index which help the query optimizer to remove any lookup which can be a key lookup or a RID lookup. A key lookup is performed in case the base table accommodates a clustered index otherwise a RID lookup is used by the query optimizer to fetch the non-key columns needed by the query. To know more about key lookup and RID lookup, click here.

The optimizer doesn’t need … More

The post Covering index and its usage appeared first on SQLRelease.

http://www.sqlrelease.com/covering-index-and-its-usage/feed 0
Unfolding | Set Based Approach | Get Continuous Start Date of the Current Project – Episode 8 http://www.sqlrelease.com/unfolding-set-based-approach-get-continuous-start-date-current-project-episode-8 http://www.sqlrelease.com/unfolding-set-based-approach-get-continuous-start-date-current-project-episode-8#comments Thu, 13 Oct 2016 05:27:56 +0000 http://www.sqlrelease.com/?p=1133 In this video, we are going to learn;

  1. How and when to use Apply operator in SQL Server, and
  2. How to compare rows on a given logic

You can download the script used in this example from below the video.


The post Unfolding | Set Based Approach | Get Continuous Start Date of the Current Project – Episode 8 appeared first on SQLRelease.

http://www.sqlrelease.com/unfolding-set-based-approach-get-continuous-start-date-current-project-episode-8/feed 1
Dynamic SQL in OLEDB source component in SSIS http://www.sqlrelease.com/dynamic-sql-in-oledb-source-component-in-ssis http://www.sqlrelease.com/dynamic-sql-in-oledb-source-component-in-ssis#comments Mon, 12 Sep 2016 05:15:11 +0000 http://www.sqlrelease.com/?p=1072 The metadata could not be determined because statement contains dynamic SQL

When we use a batch of T-SQL statements which contains dynamic SQL or uses temporary tables inside, in an OLEDB source component placed in a Data Flow Task of a SSIS package, we get an error during column names extraction because the source component gets failed to fetch the metadata (columns and their data types) for the given T-SQL batch.

In this post, we are going to learn how we can use a dynamic SQL statement or a batch of T-SQL statement which does not expose its metadata directly, in a source component which could be an OLEDB source, or an ODBC source being used to fetch data from the SQL Server.

Follow below steps to generate the error:

  • Create an integration services project in visual studio.
  • Add a Data Flow Task in the package.
  • Create an OLEDB connection


The post Dynamic SQL in OLEDB source component in SSIS appeared first on SQLRelease.

http://www.sqlrelease.com/dynamic-sql-in-oledb-source-component-in-ssis/feed 1
STRING_SPLIT function – SQL Server 2016 http://www.sqlrelease.com/string_split-function-sql-server-2016 http://www.sqlrelease.com/string_split-function-sql-server-2016#comments Fri, 19 Aug 2016 08:24:45 +0000 http://www.sqlrelease.com/?p=1108 Finally, STRING_SPLIT function, one of the most awaiting feature for a long time, has been introduced by Microsoft. In SQL Server 2016, now, we have a built-in system function to split a string with a specified separator.

Earlier, whenever we had to map a denormalized string (e.g. comma separated string values) with the values stored in a table column (normalized values) , we had to create a table valued function which could create a table from a given string value by splitting it using predefined separator. The problem with creating our own function to split the string was its performance, especially if we were not using either a CLR function or an highly optimized SQL function.

One of the most common scenario where we need this functionality very frequently is whenever we need to deal with SSRS’s multi value parameters. Reporting services supplies a comma separated string value to the … More

The post STRING_SPLIT function – SQL Server 2016 appeared first on SQLRelease.

http://www.sqlrelease.com/string_split-function-sql-server-2016/feed 1
DATEDIFF and DATEDIFF_BIG – SQL Server 2016 http://www.sqlrelease.com/datediff-and-datediff_big-sql-server-2016 http://www.sqlrelease.com/datediff-and-datediff_big-sql-server-2016#respond Tue, 16 Aug 2016 09:04:52 +0000 http://www.sqlrelease.com/?p=1100 We are already familiar with DATEDIFF function introduced in the very initial version of SQL Server. But, in SQL Server 2016, Microsoft has introduced DATEDIFF_BIG function which can be used to compute the difference between two given dates in terms of the given date part. In this post, we are going to explore the use of the DATEDIFF_BIG function.

Lets have a look on the syntax of both these functions:




Difference between DATEDIFF and DATEDIFF_BIG function

In above syntax, we can see that both the functions have similar syntax and any of them can be used to get the difference between two dates. However, these functions have different return types. DATEDIFF function returns an integer value as a difference between two dates, whereas DATEDIFF_BIG function returns a big integer value as a difference.

The range of the integer value in SQL Server is from -2,147,483,648 to … More

The post DATEDIFF and DATEDIFF_BIG – SQL Server 2016 appeared first on SQLRelease.

http://www.sqlrelease.com/datediff-and-datediff_big-sql-server-2016/feed 0
Unfolding | Set Based Approach | Create Attendance Report – Episode 7 http://www.sqlrelease.com/unfolding-set-based-approach-create-attendance-report-episode-7 http://www.sqlrelease.com/unfolding-set-based-approach-create-attendance-report-episode-7#comments Fri, 12 Aug 2016 07:24:39 +0000 http://www.sqlrelease.com/?p=1092 In this video, we are going to learn;

  1. Generate date list from the given date range dynamically
  2. Repeat the date list for each employee without using a loop or recursive CTE

You can download the script used in this example from below the video.

 … More

The post Unfolding | Set Based Approach | Create Attendance Report – Episode 7 appeared first on SQLRelease.

http://www.sqlrelease.com/unfolding-set-based-approach-create-attendance-report-episode-7/feed 1
Select all elements regardless of level in XML http://www.sqlrelease.com/select-all-elements-regardless-of-level-in-xml http://www.sqlrelease.com/select-all-elements-regardless-of-level-in-xml#comments Fri, 01 Jul 2016 06:35:25 +0000 http://www.sqlrelease.com/?p=1040 We have already published a post on “Read XML Data as a table in SQL Server” and “Read and compare XML nodes dynamically with unknown elements“. In this post, we will see that how we can skip levels in XML string to read all the elements at a given level regardless of the level name. A wildcard character * (asterisk) can be used to extract all the elements of a XML string regardless of the level name. Lets have a demo to understand this.

Suppose, we have below XML data:

In this data, the root level node is <Department> which has <HR>, <Admin>, and <Engineering> as their children nodes. Below image displays the above XML data separated by department names to make it more clear:

Now, if we want to read the name of all the employees regardless of their parent department names, we can use … More

The post Select all elements regardless of level in XML appeared first on SQLRelease.

http://www.sqlrelease.com/select-all-elements-regardless-of-level-in-xml/feed 2
Unfolding | Set Based Approach | Generate Rows Dynamically – Episode 6 http://www.sqlrelease.com/unfolding-set-based-approach-generate-rows-dynamically-episode-6 http://www.sqlrelease.com/unfolding-set-based-approach-generate-rows-dynamically-episode-6#respond Wed, 29 Jun 2016 10:10:40 +0000 http://www.sqlrelease.com/?p=1067 In this video, we are going to learn;

  1. How we can Generate rows dynamically for each record of a table in set based approach, and
  2. How to do calculations on each row of a table generated dynamically

You can download the script used in this example from below the video.


The post Unfolding | Set Based Approach | Generate Rows Dynamically – Episode 6 appeared first on SQLRelease.

http://www.sqlrelease.com/unfolding-set-based-approach-generate-rows-dynamically-episode-6/feed 0
Unfolding | Set Based Approach | Tally Table – Episode 5 http://www.sqlrelease.com/unfolding-set-based-approach-tally-table-episode-5 http://www.sqlrelease.com/unfolding-set-based-approach-tally-table-episode-5#respond Wed, 29 Jun 2016 09:28:12 +0000 http://www.sqlrelease.com/?p=1061 In this video, we are going to understand Tally table which is very useful in writing set based SQL queries. You can download the script which can be used to create the Tally table from below the video.


The post Unfolding | Set Based Approach | Tally Table – Episode 5 appeared first on SQLRelease.

http://www.sqlrelease.com/unfolding-set-based-approach-tally-table-episode-5/feed 0
Unfolding | Set Based Approach | How join works internally – Episode 4 http://www.sqlrelease.com/unfolding-set-based-approach-join-works-internally-episode-4 http://www.sqlrelease.com/unfolding-set-based-approach-join-works-internally-episode-4#respond Wed, 29 Jun 2016 06:27:07 +0000 http://www.sqlrelease.com/?p=1057 In this video, we are going to understand how join works internally. If you have a good understanding of joins and how it works, you can skip this video and move to the next video in this series. If not, lets start understanding the joins. You can download the script used in this example from below the video.

Here is the example script used in this video.… More

The post Unfolding | Set Based Approach | How join works internally – Episode 4 appeared first on SQLRelease.

http://www.sqlrelease.com/unfolding-set-based-approach-join-works-internally-episode-4/feed 0
Unfolding | Set Based Approach | SQL Server Query execution architecture – Episode 3 http://www.sqlrelease.com/unfolding-set-based-approach-sql-server-query-execution-architecture-episode-3 http://www.sqlrelease.com/unfolding-set-based-approach-sql-server-query-execution-architecture-episode-3#respond Wed, 29 Jun 2016 02:51:35 +0000 http://www.sqlrelease.com/?p=1051 In this video, we are going to understand the query execution architecture which helps us to understand the importance of set based approach. When a T-SQL statement gets submitted to SQL server, it goes through multiple steps before we get the final output. Lets have a look on SQL Server query execution architecture.


The post Unfolding | Set Based Approach | SQL Server Query execution architecture – Episode 3 appeared first on SQLRelease.

http://www.sqlrelease.com/unfolding-set-based-approach-sql-server-query-execution-architecture-episode-3/feed 0
Unfolding | Set Based Approach | Introduction to the course – Episode 2 http://www.sqlrelease.com/unfolding-set-based-approach-introduction-course-episode-2 http://www.sqlrelease.com/unfolding-set-based-approach-introduction-course-episode-2#respond Tue, 28 Jun 2016 03:42:10 +0000 http://www.sqlrelease.com/?p=1049 This video will give you insight of the topic that we are going to cover in this series. We know that the thinking in terms of sets is creative and innovative and once you start understanding the concepts, believe me, you will find it is simple too. Writing set based queries needs a good understanding of SQL joins and other set based operators with some imagination ability, which we are going to learn in this course.


The post Unfolding | Set Based Approach | Introduction to the course – Episode 2 appeared first on SQLRelease.

http://www.sqlrelease.com/unfolding-set-based-approach-introduction-course-episode-2/feed 0
Unfolding | Set Based Approach | Why set based approach – Episode 1 http://www.sqlrelease.com/unfolding-set-based-approach-why-set-based-approach-episode-1 http://www.sqlrelease.com/unfolding-set-based-approach-why-set-based-approach-episode-1#respond Mon, 27 Jun 2016 16:17:14 +0000 http://www.sqlrelease.com/?p=1041 Welcome to my course “Unfolding | Set Based Approach”. This is my first video tutorial series. In this series, I am going to share the concepts and techniques being used to create set based SQL queries.

This course is not based on how to write queries (this you can find at many places), rather it is based on how to think in set based manner. This course contains real life examples with deep insights to explore set based concepts, so that you can start thinking in terms of sets. Lets watch this video which explains why we should use set based approach instead of cursors or loops.

Please do share and comment if you like this. Also, please subscribe to our newsletter to be updated.



The post Unfolding | Set Based Approach | Why set based approach – Episode 1 appeared first on SQLRelease.

http://www.sqlrelease.com/unfolding-set-based-approach-why-set-based-approach-episode-1/feed 0
It’s time to install SQL Server 2016 http://www.sqlrelease.com/time-install-sql-server-2016 http://www.sqlrelease.com/time-install-sql-server-2016#respond Mon, 27 Jun 2016 05:16:27 +0000 http://www.sqlrelease.com/?p=1035 Microsoft has launched the SQL Server 2016. We can download and install it from here. However, when we start installation of SQL Server 2016, we can see some installation changes there. Prior to SQL Server 2016, “SQL Server Management Studio (SSMS)” was a part of the feature list of main SQL Server installation (which starts after clicking on “New SQL Server stand-alone installation or add features to an existing installation“) but now it is available on a separate install. Below is the screen shot of the feature selection list of SQL Server 2016 and SQL Server 2014:

In above image, we can see that the management tools was a feature of the core SQL Server installation process in SQL Server 2014 (right side image) but in SQL Server 2016 (left side image), it is not available in the feature list of SQL Server installation process. So, even … More

The post It’s time to install SQL Server 2016 appeared first on SQLRelease.

http://www.sqlrelease.com/time-install-sql-server-2016/feed 0
Set vs Select – Assigning variables http://www.sqlrelease.com/set-vs-select-assigning-variables http://www.sqlrelease.com/set-vs-select-assigning-variables#respond Thu, 12 May 2016 03:33:35 +0000 http://www.sqlrelease.com/?p=1010 SET and SELECT both can be used to assign values to the local variables in SQL Server. However, SET is an ANSI standard and also recommended by Microsoft to be used for variable assignment. In this post, “Set vs Select – Assigning variables“, we will explore the behavior of SET and SELECT statement during variable assignment from a query.

When we use a scalar subquery (which returns a single value) to assign a local variable using SET or SELECT, both statements behave similar. It means, if subquery returns no rows, they set variable to NULL during variable assignment. But when a column name from a query (which is not a scalar subquery) directly assigns to a local variable using SELECT statement and the query returns 0 rows, then the variable value remains unchanged.

As per its nature, SET statement uses a scalar subquery to assign a local variable … More

The post Set vs Select – Assigning variables appeared first on SQLRelease.

http://www.sqlrelease.com/set-vs-select-assigning-variables/feed 0
Change stored procedure output column names and data types http://www.sqlrelease.com/change-stored-procedure-output-column-names-data-types http://www.sqlrelease.com/change-stored-procedure-output-column-names-data-types#comments Mon, 02 May 2016 03:25:36 +0000 http://www.sqlrelease.com/?p=994 Can we change the output column name and their data type being received from a stored procedure during execution?

Yes, SQL Server 2012 introduced “WITH RESULT SETS” option which can be used with EXECUTE command to redefine the metadata of result sets being received from stored procedures. This option can handle single as well as multiple result sets.

WITH RESULT SETS” option can be useful if we want to reuse an existing stored procedure’s result set(s) with different column name and / or data type. Lets understand this with the help of an example. Below is the stored procedure named “uspGetEmployeeManagers” created in “AdventureWorks2014” datababse. This procedure return the list of managers for a given employee as below:

Imagine, this stored procedure is being used in many applications throughout organization. Now, in a new requirement, we need the same result set but … More

The post Change stored procedure output column names and data types appeared first on SQLRelease.

http://www.sqlrelease.com/change-stored-procedure-output-column-names-data-types/feed 2
The join order has been enforced because a local join hint is used – Warning in SQL Server http://www.sqlrelease.com/join-order-enforced-local-join-hint-used-warning-sql-server http://www.sqlrelease.com/join-order-enforced-local-join-hint-used-warning-sql-server#comments Tue, 26 Apr 2016 15:11:59 +0000 http://www.sqlrelease.com/?p=986 When we use a local JOIN hint in T-SQL query, sometimes, SQL Server throws a warning message as “Warning: The join order has been enforced because a local join hint is used.“. For example, below is a query with a local join hint:

After execution, we will get below warning message with result set:

In above code, we are using a local JOIN hint “INNER MERGE JOIN” which forces this query to override the physical join (which could be nested loop or merge or hash join) chosen by SQL Server with the physical join given in the query hint (which is MERGE join in this case). If you want to read more about the physical joins, visit my post “Nested loop, Merge, and Hash Joins in SQL Server“.

Here, SQL Server enforces a join order during query execution because a local join hint has … More

The post The join order has been enforced because a local join hint is used – Warning in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/join-order-enforced-local-join-hint-used-warning-sql-server/feed 3
Dynamic PIVOT query in SQL Server http://www.sqlrelease.com/dynamic-pivot-query-in-sql-server http://www.sqlrelease.com/dynamic-pivot-query-in-sql-server#comments Sat, 09 Apr 2016 04:47:15 +0000 http://www.sqlrelease.com/?p=958 PIVOT clause is used to generate cross tab outputs in SQL Server. We put unique data values from a column in the PIVOT clause to render them as multiple columns in aggregation with other columns required in the output. With the help of PIVOT clause, we can transpose the distinct values of a column into multiple columns. However, syntax of PIVOT clause requires these distinct values to be known at query design time. This kind of query can be considered as a static pivot query. We can hard code these distinct values in the PIVOT clause only if these values are fixed and static in nature.

However, when it comes to pivot uncertain values from a column, we would’t be able to cater these values in the PIVOT clause at query design time. Also, SQL Server does not provide any built in functionality which can be used in this scenario. … More

The post Dynamic PIVOT query in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/dynamic-pivot-query-in-sql-server/feed 3
Sort data in Power BI http://www.sqlrelease.com/sort-data-in-power-bi http://www.sqlrelease.com/sort-data-in-power-bi#respond Wed, 30 Mar 2016 06:48:08 +0000 http://www.sqlrelease.com/?p=953 This post “Sort data in Power BI” explains how we can sort Power BI visual data by a column which is being used in the visual itself or by some other column which is not being used in the visual itself. We know that Power BI desktop tool provides set of functionalities to create flashy and interactive reports. It supports direct connectivity with many data sources, to know more about Power BI desktop application, visit our previous post “Rise of the Power BI“, to explore drill down functionality in Power BI, visit “Drill down report in Power BI” post.

To demonstrate Power BI visual data sorting, we are going to use below sample query which is extracting internet sales data along with sales territory from AdventureWorksDW2014 database:

Below result set returned from the above sample query.

In above result set, we have “GroupName”, “CountryName”, … More

The post Sort data in Power BI appeared first on SQLRelease.

http://www.sqlrelease.com/sort-data-in-power-bi/feed 0
Insert statement http://www.sqlrelease.com/sql-server-tutorial/insert-statement http://www.sqlrelease.com/sql-server-tutorial/insert-statement#respond Sat, 27 Feb 2016 11:49:05 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=803 In this chapter “Insert statement“, we are going to discuss T-SQL’s Insert statement which is used to add new records in a table. Whenever, we need to add a record in a table, INSERT T-SQL statement is used. We can insert single or multiple records at a time using INSERT statement. INSERT statement can be used in two ways as below:

  1. To insert fixed (hard-code) values
  2. To insert the result of a SELECT statement

Let’s discuss each of them in more detail with the help of example.

To insert fixed (hard-code) values

To insert fixed values in the table, below is the syntax:


INSERT INTO [<schema-name>.]<table-name>

[(column-1, column-2, column-3, …….., column-n)]


(value-1, value-2, value-3, …….., value-n)


INSERT INTO is used to declare a new INSERT statement.

[<schema-name>.] is the name of the schema in which the table exists and is optional if the object exists … More

The post Insert statement appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-tutorial/insert-statement/feed 0
Drill down report in Power BI http://www.sqlrelease.com/drill-down-report-in-power-bi http://www.sqlrelease.com/drill-down-report-in-power-bi#respond Sun, 07 Feb 2016 07:52:21 +0000 http://www.sqlrelease.com/?p=908 In previous post “Rise of the Power BI“, we have discussed about the Power BI and it’s components. In this post “Drill down report in Power BI”, we are going to learn how we can create a drill down report in Power BI.

To demonstrate the Power BI drill down functionality, we are loading the sample data using a SQL query from “AdventureWorks2014” database. Power BI desktop provides a direct connectivity to SQL Server which we are going to use in this tutorial.

Lets, load the data into power BI to create a drill down report:

Loading data into Power BI from SQL Server

To create a SQL Server connection to pull data from AdventureWorks2014 Database, follow below steps:

  1. Open Power BI Desktop application.
  2. A dialog box will appear at startup screen, click on “Get Data” button appearing at left of the dialog box.


The post Drill down report in Power BI appeared first on SQLRelease.

http://www.sqlrelease.com/drill-down-report-in-power-bi/feed 0
Convert number into year, month, day, hour, minute and second http://www.sqlrelease.com/convert-number-into-year-month-day-hour-minute-and-second http://www.sqlrelease.com/convert-number-into-year-month-day-hour-minute-and-second#comments Fri, 22 Jan 2016 09:11:28 +0000 http://www.sqlrelease.com/?p=918 We have an integer number which represents seconds (secs) part of the time. We need to convert this integer number into year, month, days, hour, minute and second parts. Let me explain with the help of the examples to make it clear.


100 Seconds – 0 year(s) 0 month(s) 0 day(s) 0 hour(s) 1 minute(s) 40 second(s)

3600 Seconds – 0 year(s) 0 month(s) 0 day(s) 1 hour(s) 0 minute(s) 0 second(s)

86400 Seconds – 0 year(s) 0 month(s) 1 day(s) 0 hour(s) 0 minute(s) 0 second(s)

2678400 Seconds – 0 year(s) 1 month(s) 0 day(s) 0 hour(s) 0 minute(s) 0 second(s)

35110011 Seconds – 1 year(s) 1 month(s) 10 day(s) 8 hour(s) 46 minute(s) 51 second(s)


Convert number into year, month, day, hour, minute and second

Below is the code to convert the input integer number into year, month, day, hour, minute and second as above:

Or, … More

The post Convert number into year, month, day, hour, minute and second appeared first on SQLRelease.

http://www.sqlrelease.com/convert-number-into-year-month-day-hour-minute-and-second/feed 1
Rise of the Power BI http://www.sqlrelease.com/rise-of-the-power-bi http://www.sqlrelease.com/rise-of-the-power-bi#comments Wed, 16 Dec 2015 06:27:45 +0000 http://www.sqlrelease.com/?p=870 What is Power BI?

Power BI is a new cloud first self service analytic tool introduced by Microsoft which empowers us to bring our whole business data at one place for analysis purpose. It provides an easy way to pull data from multiple data sources which includes but not limited to files, databases, azure databases, Hadoop files, websites and many more.

Power BI has various components, from which Power BI Desktop tool is used to create, publish and share interactive and stunning reports. Mobile users can download the Power BI Mobile application to view these published dashboards on their mobile devices. All together, it’s a new era of interactive and mobile friendly cloud based self service reporting.

It’s a free reporting solution from Microsoft which can be used by anyone, anytime, anywhere.

Why Power BI?

Microsoft is providing a complete enterprise BI solution to the industries since more than a … More

The post Rise of the Power BI appeared first on SQLRelease.

http://www.sqlrelease.com/rise-of-the-power-bi/feed 1
Query Performance Tuning – General Guidelines http://www.sqlrelease.com/query-performance-tuning-general-guidelines http://www.sqlrelease.com/query-performance-tuning-general-guidelines#respond Sun, 29 Nov 2015 12:59:57 +0000 http://www.sqlrelease.com/?p=887 Query performance tuning – Introduction

Query performance tuning is a process of improving system performance to make it faster and more scalable. It is a creative and iterative process which has a clear and well-defined objective. To achieve this goal, we have to follow certain defined steps.

Why we need this

Enterprise data changes frequently over time, which may impact the performance of existing queries. In most of the cases, a slight change in the index or in the query can improve the performance of the query significantly. In such cases, the improvement in performance can be much better than a CPU or memory upgrade.

How to tune a query

Performance tuning process has certain steps to follow in a defined way to achieve the clearly defined objective.

In the above flow chart, you see that we begin by setting objective, followed by getting the current performance value. In case … More

The post Query Performance Tuning – General Guidelines appeared first on SQLRelease.

http://www.sqlrelease.com/query-performance-tuning-general-guidelines/feed 0
Order max and min value rows alternatively in SQL Server http://www.sqlrelease.com/order-max-and-min-value-rows-alternatively-in-sql-server http://www.sqlrelease.com/order-max-and-min-value-rows-alternatively-in-sql-server#respond Sun, 04 Oct 2015 09:51:40 +0000 http://www.sqlrelease.com/?p=868 In this blog post “Order max and min value rows alternatively in SQL Server”, we are going to learn how we can order the rows of a table by combining max and min value rows alternatively. For example, from an employee table based on the salary column, we need to extract the records ordered as;

First row: First highest salary

Second row: First lowest salary

Third row: Second highest salary

Fourth row: Second lowest salary

Fifth row: Third highest salary

Sixth row: Third lowest salary

and so on…….

We know that the SQL Server database engine is optimized to operate in a set oriented way instead of RBAR (Row By Agonizing Row, processing row by row in a loop). We are going to achieve the desired output in a set based approach, unlike loops or recursive CTEs. Let’s have this tutorial in action now.

Create the dummy employee table and … More

The post Order max and min value rows alternatively in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/order-max-and-min-value-rows-alternatively-in-sql-server/feed 0
Add constraint without checking existing data http://www.sqlrelease.com/add-constraint-without-checking-existing-data http://www.sqlrelease.com/add-constraint-without-checking-existing-data#respond Tue, 22 Sep 2015 06:28:38 +0000 http://www.sqlrelease.com/?p=796 In this post “Add constraint without checking existing data” we are going to learn how we can add a constraint on a column which already has invalid data. We create constraints to automatically enforce the integrity of the database. Using constraints we can define the rules for valid set of values for a given column. Let’s learn how we can instruct SQL Server to ignore check on the existing data during constraint creation on a column.

We have an employee table with columns EmpId, EmpName and ContactNumber. Column ContactNumber holds few invalid values, as we don’t had a constraint on this column. Now, we want to accept only valid values in the contact number column being validated with the custom business logic, but we don’t want to remove or modify the already existing data in the column. We need to put a constraint for coming data and not for existing … More

The post Add constraint without checking existing data appeared first on SQLRelease.

http://www.sqlrelease.com/add-constraint-without-checking-existing-data/feed 0
Change chart type dynamically SSRS http://www.sqlrelease.com/change-chart-type-dynamically-ssrs http://www.sqlrelease.com/change-chart-type-dynamically-ssrs#respond Sun, 13 Sep 2015 11:08:28 +0000 http://www.sqlrelease.com/?p=799 Today, we are going to learn how we can change chart type dynamically depending on the selected value in the report parameter in SSRS (SQL Server Reporting Services) report. Report parameter has few predefined chart type as values in the report, and depending on the selected value in the parameter, chart renders in the report.

We know that there is no any inbuilt way which can be used to change the chart type at run time in SSRS and to achieve this we need to forge a couple of things. In this post we will discuss a method which can be used to achieve this. For demo, I am using AdventureWorks2014 database in this tutorial. I have attached the zipped project file which can be downloaded from here or from the link provided at the bottom end of this post.

Let’s create a dummy project in SSDT to demonstrate how … More

The post Change chart type dynamically SSRS appeared first on SQLRelease.

http://www.sqlrelease.com/change-chart-type-dynamically-ssrs/feed 0
Index on computed column http://www.sqlrelease.com/index-on-computed-column http://www.sqlrelease.com/index-on-computed-column#comments Tue, 08 Sep 2015 07:23:46 +0000 http://www.sqlrelease.com/?p=795 Today, we are going to learn how we can create index on a computed column which improves the performance of SELECT queries. To create a computed column, we will use an user defined function instead of inline code. Also to know about computed columns, refer my previous blog post “What is Computed Column in sql server“.

Create index on computed column

Let’s create a function, “dbo.fn_GetTotalCourseFee“, which accepts @CourseFee and @TaxPercentage as input parameters and returns the computed @TotalFee amount. To highlight some important prerequisites related to index creation on computed column, I have used a function, otherwise we can also use the inline code in column definition.

Below is the function being used to create a computed column:

Note that the above function is created with schema bind clause “WITH SCHEMABINDING” which is must required to allow indexing on the computed column, otherwise … More

The post Index on computed column appeared first on SQLRelease.

http://www.sqlrelease.com/index-on-computed-column/feed 2
Querying temporal table data http://www.sqlrelease.com/querying-temporal-table-data http://www.sqlrelease.com/querying-temporal-table-data#respond Sun, 23 Aug 2015 03:43:57 +0000 http://www.sqlrelease.com/?p=769 We have discussed what is a temporal table, how we can create it, and what are the limitations of a temporal table. We have also discussed how we can convert an existing table to a temporal table in our previous posts.

In this post “querying temporal table data” we are going to learn how to query the time varying data from a temporal table.

In SQL Server 2016, we have a new clause FOR SYSTEM_TIME, which has four new sub clauses to query temporal table data:

  1. AS OF <datetime>
  2. FROM <start_datetime> TO <end_datetime>
  3. BETWEEN <start_datetime> AND <end_datetime>
  4. CONTAINED IN (start_datetime, end_datetime)

Let’s create a temporal table with dummy data to query with FOR SYSTEM_TIME clause and its sub clauses with examples. Below script is used to create a temporal table and to insert few dummy rows in the table with SQL Server default datetime value (1900-01-01) … More

The post Querying temporal table data appeared first on SQLRelease.

http://www.sqlrelease.com/querying-temporal-table-data/feed 0
Convert existing table to temporal table http://www.sqlrelease.com/convert-existing-table-to-temporal-table http://www.sqlrelease.com/convert-existing-table-to-temporal-table#comments Thu, 20 Aug 2015 04:02:49 +0000 http://www.sqlrelease.com/?p=750 In the previous post, we have discussed the temporal table, which is introduced in SQL Server 2016 to store the time varying data (current data and the data change history along with the time period). There, we have also learnt how we can create a temporal table from scratch.

In this post “Convert existing table to temporal table“, we are going to learn how we can convert an existing table to a temporal table. For the demo purpose we are using a dummy employee table, created with a very small subset of the data taken from HumanResources.Employee table of adventure works database.

Below is the dummy table which needs to be converted in a temporal table:

We can use below script to create the above sample table with the data for demo purpose:

Convert existing table to temporal table – Step by step

We are going to … More

The post Convert existing table to temporal table appeared first on SQLRelease.

http://www.sqlrelease.com/convert-existing-table-to-temporal-table/feed 3
Temporal Table in SQL Server http://www.sqlrelease.com/temporal-table-in-sql-server http://www.sqlrelease.com/temporal-table-in-sql-server#comments Sat, 01 Aug 2015 12:48:25 +0000 http://www.sqlrelease.com/?p=726 In this post we are going to discuss “Temporal Table”, a new feature introduced in SQL Server 2016. Lets start this post “Temporal Table in SQL Server” with the definition of temporal table.

Temporal Table facilitates inbuilt support for data change tracing along with the time period in a table. It holds the current as well as historical data to determine the values of a record at any given period of time. Temporal table uses a pair of tables; current table and an associated history table, to store current and historical data respectively. It uses two system columns of data type datetime2 to record start time and end time in both tables (current and history) to enable record versioning.

We can easily manage the data change history in a table using temporal tables which was a bit cumbersome and manual task in the previous versions of Microsoft SQL Server. Temporal … More

The post Temporal Table in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/temporal-table-in-sql-server/feed 1
SELECT Statement http://www.sqlrelease.com/sql-server-tutorial/select-statement http://www.sqlrelease.com/sql-server-tutorial/select-statement#respond Mon, 27 Jul 2015 06:49:08 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=688 Now that we have been familiar with Create, Alter and Drop – Database and Table, it is time to be familiar with T-SQL statements. Let’s start this chapter with the definition of T-SQL followed by a detailed discussion on T-SQL’s SELECT statement.

Transact SQL (T-SQL)

Transact SQL (T-SQL) is a proprietary extension of SQL (structured Query Language) by Microsoft and Sybase to communicate with Microsoft SQL Server. T-SQL has support for procedural programming using control flow (if-else, Case), loop (while), cursor, recursion and local variable, etc. It has many inbuilt functions to support string operation, date and time processing, mathematical calculation, aggregate processing and many more.

In short, T-SQL is capable to deal all kinds of SQL Server requirements like; creating database, adding tables, creating relationship, constraints, managing users and roles, creating a backup, restore database etc.

T-SQL Statements

T-SQL Statements are the basic constructs of T-SQL Programming … More

The post SELECT Statement appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-tutorial/select-statement/feed 0
Get hierarchical data in order http://www.sqlrelease.com/get-hierarchical-data-in-order http://www.sqlrelease.com/get-hierarchical-data-in-order#comments Tue, 21 Jul 2015 11:27:52 +0000 http://www.sqlrelease.com/?p=709 In this post, we are going to learn how we can get hierarchical data in order. We are dealing with a user defined hierarchical data which can have “n” number of siblings and their siblings can also have “n” number of siblings in turn.

For demo purpose, we have a Product_Master table, in which a product can be marked as a parent of another product, and that child product can also be marked as a parent of another product, such kind of hierarchy is known as user defined hierarchy. As any product can be marked as another product’s parent, we can have any number of nested products in the hierarchy. We have to retrieve all these products with their associated parent in ordered way.

Ordered hierarchical data from above user defined hierarchy, can be achieved with a recursive common table expression (CTE) or using a loop. We … More

The post Get hierarchical data in order appeared first on SQLRelease.

http://www.sqlrelease.com/get-hierarchical-data-in-order/feed 2
Role playing dimension http://www.sqlrelease.com/role-playing-dimension http://www.sqlrelease.com/role-playing-dimension#respond Sun, 19 Jul 2015 14:37:10 +0000 http://www.sqlrelease.com/?p=700 We have explored Junk dimension and Degenerate dimension in previous posts, now we are going to discuss Role playing dimension in this post. Lets start with the definition followed by an example.

Role playing dimension

A fact table keeps the facts of a business process. It is built of two types of columns: measure columns and dimension key columns. Measure are the quantitative business data about the business process and dimension keys reference to the dimension tables which hold the textual attributes of the business process.

Typically a dimension key column of a fact table refers a dimension table but its also very common where multiple columns of a fact table refer to a single dimension table. When a single dimension table is linked from multiple dimension key columns of a fact table, that dimension table is known as role playing dimension. As multiple columns of a fact table … More

The post Role playing dimension appeared first on SQLRelease.

http://www.sqlrelease.com/role-playing-dimension/feed 0
Degenerate dimension http://www.sqlrelease.com/degenerate-dimension http://www.sqlrelease.com/degenerate-dimension#comments Wed, 15 Jul 2015 12:21:51 +0000 http://www.sqlrelease.com/?p=690 We have discussed the use of junk dimensions in data modelling and in this post we are going to explore Degenerate dimension. Lets start with the definition.

Degenerate Dimension

A high cardinality attribute column in the fact table which does not have any other content except its natural key and is required as a dimension for analysis or drill-down purpose, is called a degenerate dimension. As this degenerate dimension is constructed from a fact table item and is placed in the fact table, it is also known as fact dimension. It helps to reduce duplicate data by placing high cardinality dimension key in the fact table.

Degenerate dimension keys are significantly unique and are nearly as large as fact table. Moving this attribute in a single column dimension table requires a considerably large dimension table, and you would also need to join the surrogate key of the fact … More

The post Degenerate dimension appeared first on SQLRelease.

http://www.sqlrelease.com/degenerate-dimension/feed 1
Create, Alter and Drop – Database and Table http://www.sqlrelease.com/sql-server-tutorial/create-alter-and-drop-database-and-table http://www.sqlrelease.com/sql-server-tutorial/create-alter-and-drop-database-and-table#comments Sat, 11 Jul 2015 06:36:45 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=659 Now that you are familiar with database concepts and SQL Server Management Studio, it is time to begin our journey with T-SQL programming. In my opinion, to shine as a good T-SQL programmer, one must have a good understanding of T-SQL concepts and its capability.

In this chapter “Create, Alter and Drop – Database and Table”, we are going to learn, how we can create, alter and drop a database and table. We would also explore how to add columns to an existing table, change column definition and delete column from the table.

Below is the abstract of this chapter:

  1. {CREATE | ALTER | DROP} DATABASE – Used to create / alter / delete a database respectively.
  2. {CREATE | ALTER | DROP} TABLE – Used to add / modify / remove table in a database respectively.




We … More

The post Create, Alter and Drop – Database and Table appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-tutorial/create-alter-and-drop-database-and-table/feed 1
Junk dimension http://www.sqlrelease.com/junk-dimension http://www.sqlrelease.com/junk-dimension#comments Thu, 09 Jul 2015 11:40:18 +0000 http://www.sqlrelease.com/?p=665 What is a Junk Dimension? Have you ever come across a scenario where many small dimension tables connect (using foreign key) to the fact table? In data warehouse, we have two types of tables, Fact and Dimension. Fact table contains business facts as measures and references to the dimension tables. Dimension tables have attributes which contains textual information of business facts and are used to filter and label the data.

Typically, fact tables are deeper whereas dimension tables are wider. Sometimes it happens that we have many narrow and low cardinality (low cardinality : few number of rows in the table) dimensions in the system; like flags and indicators. To keep all these information in fact table, we need to connect all these dimension tables (available in system or created from flag and indicator attributes) with fact table. Connecting all these small dimension tables converts fact table in … More

The post Junk dimension appeared first on SQLRelease.

http://www.sqlrelease.com/junk-dimension/feed 5
Exploring SQL Server Management Studio http://www.sqlrelease.com/sql-server-tutorial/exploring-sql-server-management-studio http://www.sqlrelease.com/sql-server-tutorial/exploring-sql-server-management-studio#comments Thu, 02 Jul 2015 11:20:01 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=634 In this SQL Server Tutorial, we have gone through DBMS, RDBMS and SQL ServerTable RelationshipsData IntegrityTypes of keys and Database normalization chapters. Now that we have a good understanding of database concepts, it is time to put our feet in T-SQL.

Before we begin our journey with T-SQL (MS SQL Server programming language) we need to be familiar with SQL Server Management Studio, also known as SSMS, an application software developed by Microsoft, to manage, configure and administer Microsoft SQL Server and all its components like Database Engine, Analysis services, Integration Services, Reporting Services etc. SQL Server Management Studio provides a centralized management platform for all kind of SQL related work. We can create a database, add tables, create relationships, constraints, functions, procedures, views, triggers etc. We can also define authorization on objects like who is authorized on which object and for what.

Lets … More

The post Exploring SQL Server Management Studio appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-tutorial/exploring-sql-server-management-studio/feed 1
Generate serial number for each consecutive set of numbers http://www.sqlrelease.com/generate-serial-number-for-each-consecutive-set-of-numbers http://www.sqlrelease.com/generate-serial-number-for-each-consecutive-set-of-numbers#comments Sun, 28 Jun 2015 08:16:25 +0000 http://www.sqlrelease.com/?p=622 In this post, we are going to generate serial number for each consecutive set of numbers in a given column. We have a table tbl_Donation with columns EmpId and DonationYear. For each consecutive set of years of each employee, we need to generate serial numbers. If employee “X” donated in 2006, 2007 and 2008 years consecutively and then in 2010 and 2011, we have to assign 1 for 2005, 2 for 2006, 3 for 2007 followed by 1 for 2010 and 2 for 2011. We need to generate incremental series for each consecutive set of years but as and when a gap occurs between donation years, series has to be restarted with 1.

PARTITION BY clause in a ROW_NUMBER() window function could be able to generate the required output, if we had same number along with donation years for each consecutive set of years for all employees. Initially, we … More

The post Generate serial number for each consecutive set of numbers appeared first on SQLRelease.

http://www.sqlrelease.com/generate-serial-number-for-each-consecutive-set-of-numbers/feed 2
Database normalization http://www.sqlrelease.com/sql-server-tutorial/database-normalization http://www.sqlrelease.com/sql-server-tutorial/database-normalization#respond Sat, 27 Jun 2015 08:14:35 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=563 In previous chapter, “Types of keys“, we had a good discussion on keys and their types in SQL Server. In this chapter “Database normalization”, we are going to discuss database normalization process and normal forms. Lets start our discussion with definition of Normalization.


Normalization is a process of minimizing redundant data from database by decomposing the columns of a table into multiple tables. This process increases the number of tables in the database but it minimizes the redundant (duplicate), inaccurate and inconsistent data in database. Decomposed tables are connected using relationships (primary keys and foreign keys) to reduce the insert, update and delete anomalies. During normalization process, database designer decides the actual structure of the tables and their relationships. It is easy to find and fix any design problem at this early stage. During normalization process, we have various normal forms with some conditions. A table … More

The post Database normalization appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-tutorial/database-normalization/feed 0
CHAR, NCHAR, VARCHAR and NVARCHAR default length http://www.sqlrelease.com/char-nchar-varchar-and-nvarchar-default-length http://www.sqlrelease.com/char-nchar-varchar-and-nvarchar-default-length#respond Sat, 20 Jun 2015 13:18:54 +0000 http://www.sqlrelease.com/?p=570 What is the default length of CHAR, NCHAR, VARCHAR and NVARCHAR when we don’t specify their length in their length argument? If we omit the size of CHAR, NCHAR, VARCHAR and NVARCHAR, how they behave? In this post “CHAR, NCHAR, VARCHAR and NVARCHAR default length”, we are going to discuss the default length of CHAR, NCHAR, VARCHAR and NVARCHAR data types, if length is not specified in their argument.

I would strongly suggest to define the length of CHAR, NCHAR, VARCHAR and NVARCHAR data types as per the need. In this post, I just explain the behavior of CHAR, NCHAR, VARCHAR and NVARCHAR data types, if length is omitted, and not encouraging to omit the size of these data types.

We can define these data types as below:

char [ ( n ) ]
nchar [ ( n ) ]
varchar [ ( n | max ) ]
nvarchar [ More

The post CHAR, NCHAR, VARCHAR and NVARCHAR default length appeared first on SQLRelease.

http://www.sqlrelease.com/char-nchar-varchar-and-nvarchar-default-length/feed 0
Types of keys http://www.sqlrelease.com/sql-server-tutorial/types-of-keys http://www.sqlrelease.com/sql-server-tutorial/types-of-keys#comments Wed, 10 Jun 2015 06:58:25 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=529 In previous chapter, we had a good discussion on “Data Integrity” and in this chapter “Types of Keys”, we are going to discuss Keys and their types in SQL Server. Lets start this topic by defining keys”.

What is Key?

Keys are fields in a table which participate in below activities in RDBMS systems:

  1. To create relationships between two tables.
  2. To maintain uniqueness in a table.
  3. To keep consistent and valid data in database.
  4. Might help in fast data retrieval by facilitating indexes on column(s).

SQL Server supports various types of keys, which are listed below:

  1. Candidate Key
  2. Primary Key
  3. Unique Key
  4. Alternate Key
  5. Composite Key
  6. Super Key
  7. Foreign Key

Before discussing each type in brief, have a look on the below image used as an an example to define types of keys.

Lets discuss each type in detail:

Candidate Key

Candidate key is a key of a … More

The post Types of keys appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-tutorial/types-of-keys/feed 4
Insert into table with one identity column only http://www.sqlrelease.com/insert-into-table-with-one-identity-column-only http://www.sqlrelease.com/insert-into-table-with-one-identity-column-only#comments Sat, 06 Jun 2015 09:50:05 +0000 http://www.sqlrelease.com/?p=521 One of my friend asked me a question that “How we can insert values in a table with only one column which is identity, without using IDENTITY_INSERT ON?”. In this post “Insert into a table with one identity column only”, I am going to share a nice method to achieve this.

We know that using “SET IDENTITY_INSERT TableName ON” command, we can easily insert rows in an identity column. As per MSDN, we need to keep few things in mind related to “IDENTITY_INSERT ON”:

  1. Only one table can have IDENTITY_INSERT as ON in one session at a time. We must have to use “SET IDENTITY_INSERT TableName OFF” to use IDENTITY_INSERT on other tables.
  2. To execute IDENTITY_INSERT on a table, a user must own the table or has ALTER permission on the table. Only below types of user can execute IDENTITY_INSERT on a table:
    1. A member of sysadmin fixed server role


The post Insert into table with one identity column only appeared first on SQLRelease.

http://www.sqlrelease.com/insert-into-table-with-one-identity-column-only/feed 2
Delete all rows from all tables http://www.sqlrelease.com/delete-all-rows-from-all-tables http://www.sqlrelease.com/delete-all-rows-from-all-tables#comments Wed, 03 Jun 2015 17:04:53 +0000 http://www.sqlrelease.com/?p=511 Have you ever come across the problem to delete all rows from all tables available in a database? One of my colleague asked me this question that how can we delete all rows from all tables of a database. So, in this post, we are going to discuss, how we can delete all rows from all tables of a SQL Server database.

To delete all rows from a table named ProductCategory, we can simply use “DELETE FROM ProductCategory” command. But in case the table is being referred by a foreign key constraints from some tables and / or fires a trigger to insert few rows in an another table in the database, we must have to delete all related rows from child tables before we start deleting parent table rows. We also need to delete records from those table which are getting inserted rows as a result of a … More

The post Delete all rows from all tables appeared first on SQLRelease.

http://www.sqlrelease.com/delete-all-rows-from-all-tables/feed 2
Data Integrity http://www.sqlrelease.com/sql-server-tutorial/data-integrity Sun, 31 May 2015 12:00:01 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=456 After having a good discussion on “Table Relationships” in previous chapter, we are going to discuss Data Integrity in this chapter. First, we would discuss the term Data Integrity, followed by a discussion on data integrity types, and finally, we would go through an image which summarizes the data integrity concepts in one sight view. Lets start the discussion with the definition first.

Data Integrity

In relational database management systems, data integrity ensures the accuracy, reliability and consistency of the data during any operation like as data manipulation, data retrieval, data storage, backup or restore operation etc. It also guarantees that the recording of data is accurate and as intended. Having any bad or unintended data in the database, is a failure of data integrity. For example, having sales detail in Sales table of a product not available in Product master is a failure of referential integrity.

Below … More

The post Data Integrity appeared first on SQLRelease.

Table Relationships http://www.sqlrelease.com/sql-server-tutorial/table-relationships http://www.sqlrelease.com/sql-server-tutorial/table-relationships#respond Wed, 20 May 2015 17:25:09 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=455 We have already been familiar with “DBMS, RDBMS and SQL Server” in previous chapter. In this chapter named “Table Relationship”, we are going to understand the relationship between tables. In relational database management systems, tables are used to store every information in the form of columns and rows. Before moving to the topic “Table Relationship”, we would have a look on the definition of Database, Table, Column and Row, as these entities participate in relationships.


Database is an organized collection of data for fast processing on these data. These data are arranged in such form that enables fast retrieval of information and manipulation on these data. In RDBMSs, database organizes its data in relational form only using tables, column and rows. We can define relationships between these tables.


A table is a collection of related data in a structured form using columns and rows within a database. … More

The post Table Relationships appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-tutorial/table-relationships/feed 0
DBMS, RDBMS and SQL Server http://www.sqlrelease.com/sql-server-tutorial/dbms-rdbms-and-sql-server http://www.sqlrelease.com/sql-server-tutorial/dbms-rdbms-and-sql-server#comments Sun, 10 May 2015 05:44:53 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=386 Lets start this tutorial with the chapter “DBMS, RDBMS and SQL Server”. Before starting T-SQL part of the SQL Server tutorial, we will learn basic concepts of database systems. In this chapter, we will explore “Database management systems” and its relational extension “Relational database management systems”. We will also have an introduction to Microsoft SQL Server at the end of the chapter. This chapter has necessary images to explain the concepts in pictured way which will help you to understand the topics with ease.

Database management system (DBMS)

Database management system is a software used to define, record, query, update and manage data in a database. DBMS stores data in a structured way (relational, hierarchical, flat files, objects etc), and executes operations requested by various users on these data. It interacts with user, receives commands, and runs it against the database. DBMS can interact with some other applications, if required. … More

The post DBMS, RDBMS and SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-tutorial/dbms-rdbms-and-sql-server/feed 1
SQL Server Tutorial – Prerequisite http://www.sqlrelease.com/sql-server-tutorial/sql-server-tutorial-prerequisite http://www.sqlrelease.com/sql-server-tutorial/sql-server-tutorial-prerequisite#comments Sun, 10 May 2015 05:30:54 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=385 To start with this tutorial, you need to download and install SQL Server (Latest version recommended) from Microsoft and to do some hands-on throughout this tutorial and for assignments purposes, you need to download and attach AdventureWorksDatabase also. Below you have some links, which might help you out in these prerequisites.


Just two things for this “SQL Server Tutorial” and you all set to go with this tutorial.

  1. Install SQL Server – [Recommended – SQL Server 2014 or 2012]
  2. Download and attach “AdventureWorksDatabase”

If you don’t have installed SQL Server yet, no worries, here are the links which may help you.

To download SQL Server 2014;


For Step by Step installation of SQL Server 2014


To download AdventureWorks2014 Database


How to restore “AdventureWorks2014” Database

Download the MS Word file from below link and follow the instructions mentioned in “Install Adventure Works 2014 OLTP database from More

The post SQL Server Tutorial – Prerequisite appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-tutorial/sql-server-tutorial-prerequisite/feed 2
SQL Server Tutorial – About http://www.sqlrelease.com/sql-server-tutorial/sql-server-tutorial-about http://www.sqlrelease.com/sql-server-tutorial/sql-server-tutorial-about#comments Sun, 10 May 2015 05:26:50 +0000 http://www.sqlrelease.com/?post_type=sql-server-tutorial&p=384 SQL Server Tutorial – Step by Step

About this tutorial

You are welcome at my first tutorial, titled as “SQL Server Tutorial“. If I am not wrong, it seems that you are keen to learn SQL Server database programming. This “SQL Server Tutorial” is specially written for novice programmers. It starts with simple Database concepts and takes a deep dive into T-SQL. You just have to follow this tutorial to learn the skill. Well organised chapters in easy to understand language, complemented with good assignments to work on, should help you acquire the knowledge swiftly.

This SQL Server Tutorial written for Microsoft SQL Server database programming and has its primary focus in T-SQL (Transact SQL, Microsoft proprietary extension to SQL). I have worked a lot to make the content easy to understand, yet impressive. You will get a lot of real life examples, images to understand the concepts … More

The post SQL Server Tutorial – About appeared first on SQLRelease.

http://www.sqlrelease.com/sql-server-tutorial/sql-server-tutorial-about/feed 1
Mutable logical condition in CASE expression http://www.sqlrelease.com/mutable-logical-condition-in-case-expression http://www.sqlrelease.com/mutable-logical-condition-in-case-expression#comments Sun, 03 May 2015 05:32:45 +0000 http://www.sqlrelease.com/?p=391 In our previous blog post Different data types in case expression, we have explored the behavior of CASE expression in case of different data types in “THEN” and “ELSE” part. Now in this post “Mutable logical condition in CASE expression”, we are going to unfold the behavior of CASE expression when we have a non deterministic function in logical expression (WHEN part).

Mutable logical condition in CASE expression

Have a look on the below query:


In above query, logical expression “ABS(CHECKSUM(NEWID())) % 3” of CASE expression, has a non deterministic function NEWID() wrapped inside a CHECKSUM function to generate some random number on fly. Going further the CHECKSUM value has also wrapped inside a ABS function which insures a positive number. Finally there is a Mod operator with value 3 which narrows down the output result to 0 or 1 or 2 only. To catch this output, inside … More

The post Mutable logical condition in CASE expression appeared first on SQLRelease.

http://www.sqlrelease.com/mutable-logical-condition-in-case-expression/feed 6
Different data types in case expression http://www.sqlrelease.com/different-data-types-in-case-expression http://www.sqlrelease.com/different-data-types-in-case-expression#comments Thu, 30 Apr 2015 15:24:21 +0000 http://www.sqlrelease.com/?p=387 In this blog post titled as “Different data types in case expression”, we will explore the behavior of CASE expression when dealing with different data types in THEN part (true) and ELSE part (false) of CASE expression. We will limit the scope of discussion of this post to data conversion issue only. If you are interested to explore more about the CASE expression, visit this MSDN link.

What is the Return type of CASE expression

As per MSDN, CASE expression returns the highest precedence type from the given set of types in THEN and ELSE part (true and false part). To explore data type precedence, you can visit Data Type Precedence link here.

Lets play with a simple demo to see this return type in action. This demo is for test and may look a bit silly. In below SQL query, we have two variables, @RetValThen as DATETIME … More

The post Different data types in case expression appeared first on SQLRelease.

http://www.sqlrelease.com/different-data-types-in-case-expression/feed 5
Unique Key is Clustered or Nonclustered http://www.sqlrelease.com/unique-key-is-clustered-or-nonclustered http://www.sqlrelease.com/unique-key-is-clustered-or-nonclustered#comments Fri, 17 Apr 2015 16:47:48 +0000 http://www.sqlrelease.com/?p=362 An easy question for you “Unique Key is Clustered or Nonclustered”? Lets explain in more detail, When I create a Unique key on a table without explicitly defining the type of index(clustered or nonclustered), which type of index will be used to accommodate the key?

I have already written a blog on behavior of primary key for clustered and nonclustered index type selection in such kind of scenarios and here is the link. In this post titled as “Unique Key is Clustered or Nonclustered”, we will explore the behavior of Unique Key in regards of Clustered and Nonclustered index type selection. Before going forward, I would like to focus on the differences between Primary Key and Uniquer Key below.

Difference between Primary Key and Unique Key

 Primary key

  1. It is a column or set of columns, used to uniquely identify each row of the given table.
  2. NULL values


The post Unique Key is Clustered or Nonclustered appeared first on SQLRelease.

http://www.sqlrelease.com/unique-key-is-clustered-or-nonclustered/feed 2
Rename Table and Change Schema with SP_RENAME http://www.sqlrelease.com/rename-table-and-change-schema-with-sp_rename http://www.sqlrelease.com/rename-table-and-change-schema-with-sp_rename#respond Sun, 15 Mar 2015 10:56:31 +0000 http://www.sqlrelease.com/?p=307 In this post “SP_RENAME table with schema change” I will share a trick to rename a table using sp_rename and then transfer it schema. As we know that we can use SP_RENAME system stored procedure to rename user created objects like tables, procedures, functions, views, indexes, columns, user defined types, CLR user defined types etc in current database.

For example, if you have a table with name “TestTableA” in schema “dbo” and want to change its name to “TestTableB”, you can use below command;

But in case you want to change the table name with schema change using procedure “sp_rename”, putting “Schemaname.Tablename” as new name in second parameter, will not work. What will happen if we put “Schemaname.Tablename” as new name and why it will happen, I have explained it in next section of this blog post.

Schema.TableName as New Name in sp_rename will not work

In case you want … More

The post Rename Table and Change Schema with SP_RENAME appeared first on SQLRelease.

http://www.sqlrelease.com/rename-table-and-change-schema-with-sp_rename/feed 0
NOLOCK table hint http://www.sqlrelease.com/nolock-table-hint http://www.sqlrelease.com/nolock-table-hint#comments Sat, 07 Mar 2015 10:25:15 +0000 http://www.sqlrelease.com/?p=305 A lot of people use NOLOCK table hint in their SELECT queries, some of them are expert and well aware of its pros and cons, but some are not. So, In this post we are going to focus on this table hint and its impact.

What is NOLOCK

NOLOCK and READUNCOMMITTED hints used with SELECT queries to get the data without issuing shared lock (which prevents modification of data by other transactions during read operation) on the data, and also allows to read the data acquired with exclusive lock by other transactions. NOLOCK hint is equivalent to READUNCOMMITTED isolation level which is least restrictive in SQL Server. It does not restrict the dirty reads and increases the concurrency by reducing blocking.

It holds a Sch-S (Schema stability) lock during its execution scope which blocks the transactions requesting for Sch-M (Schema modification) lock, required by DDL operations. Reverse is also true … More

The post NOLOCK table hint appeared first on SQLRelease.

http://www.sqlrelease.com/nolock-table-hint/feed 9
Divide rows of a column in two columns http://www.sqlrelease.com/divide-rows-of-a-column-in-two-columns http://www.sqlrelease.com/divide-rows-of-a-column-in-two-columns#comments Sun, 08 Feb 2015 10:07:49 +0000 http://www.sqlrelease.com/?p=300 In this post “Divide rows in two columns”, we are going to learn a trick to divide a column’s rows in two columns. We have find the total number of rows and then distribute it in two columns, For example, a table with a column containing 6 rows, will split in two columns, each of 3 rows. In case of odd numbers of rows in the column, in second column, a blank string should appear for last entry. Lets have a look on the below table and required output to understand this;

Divide rows in two columns

Required output

Divide rows in two columns

You can see in above figures, we have 7 rows in our demo table and these rows have been distributed in two columns. Hence, we have a odd count for total rows, last row in column2 has a blank value. Below is the demo table with sample data.

Create a demo table with sample data

In … More

The post Divide rows of a column in two columns appeared first on SQLRelease.

http://www.sqlrelease.com/divide-rows-of-a-column-in-two-columns/feed 5
Text wrapping in SSRS Reports in ReportViewer Control http://www.sqlrelease.com/text-wrapping-in-ssrs-reports-in-reportviewer-control http://www.sqlrelease.com/text-wrapping-in-ssrs-reports-in-reportviewer-control#comments Fri, 23 Jan 2015 09:38:40 +0000 http://www.sqlrelease.com/?p=294 In this blog post “Report Viewer wrap text”, we are going to learn an important trick of text wrapping in SSRS reports for long texts (without space and any separator) exceeding the width of a report column’s defined width and being rendered in a Report Viewer control of .Net  Application. Below is the problem explanation in more detail;

I have a report which is rendering through a ReportViewer control in a .Net Web Application. I have defined the width of each and every column in my report. As there are multiple columns in my report and some of which contains long texts without any space or separator. What i want, if the text is too long to fit as per the defined width, the text should be wrapped in next row. I don’t want to expand the column width to accommodate this text in one row. In other words, I


The post Text wrapping in SSRS Reports in ReportViewer Control appeared first on SQLRelease.

http://www.sqlrelease.com/text-wrapping-in-ssrs-reports-in-reportviewer-control/feed 2
Count of total spaces in a string in SQL Server – Various methods http://www.sqlrelease.com/count-of-total-spaces-in-a-string-in-sql-server-various-methods http://www.sqlrelease.com/count-of-total-spaces-in-a-string-in-sql-server-various-methods#comments Thu, 22 Jan 2015 09:12:00 +0000 http://www.sqlrelease.com/?p=289 In this post we are going to find the total number of spaces in a given string. I have a string which contains spaces at multiple places and i just want to count them all. We can achieve this in various ways. Here, i am sharing some of these methods. Why i am doing this in various ways and sharing with you is just to show you the performance of different approaches of problem solving and also to share some interesting tricks to solve this problem in different manners. I am not going to cover all the possible ways to solve this problem and in fact you can achieve this in some other ways too. In case you want to share your own method, I welcome it you all to share this in comment section of this post.

Create a demo table as below and then put some demo data … More

The post Count of total spaces in a string in SQL Server – Various methods appeared first on SQLRelease.

http://www.sqlrelease.com/count-of-total-spaces-in-a-string-in-sql-server-various-methods/feed 6
Convert rows into comma separated values in a column http://www.sqlrelease.com/convert-rows-into-comma-separated-values-in-a-column http://www.sqlrelease.com/convert-rows-into-comma-separated-values-in-a-column#comments Thu, 01 Jan 2015 08:35:03 +0000 http://www.sqlrelease.com/?p=283 In this post, we are going to learn a technique to combine all the values of a row (based on a particular condition) with a separator, in a column along with other columns. What i meant by this let me explain it in more detail. Have a look on below question as raised by a colleague;

I have a Students table and a Subjects table. One student has been assigned to multiple Subjects in a transaction table. I want to extract the name of all the Subjects for which the student is assigned in a comma separated way along with other details of the student. If student is not assigned yet, i want to show a “Not Assigned Yet” value for those records.

To achieve this task, i have created a demo script and sharing the same with all the details. Below you can find the table structures and demo … More

The post Convert rows into comma separated values in a column appeared first on SQLRelease.

http://www.sqlrelease.com/convert-rows-into-comma-separated-values-in-a-column/feed 12
Count of total not null values from all columns of a table http://www.sqlrelease.com/count-of-total-not-null-values-from-all-columns-of-a-table http://www.sqlrelease.com/count-of-total-not-null-values-from-all-columns-of-a-table#comments Fri, 26 Dec 2014 08:09:38 +0000 http://www.sqlrelease.com/?p=279 In this post, we will count not null values from all the columns of a given table. One of my friend asked me to get the count of all not null values from all the columns of a given table. I used a CASE statement in my query and achieved this task but again i thought can i do this with the help of COUNT function too? And then i found an another way to achieve this task too. Here i am sharing both the ways. I am also sharing a trick to find only NULL values too.
To demonstrate this first create a table and put some demo data as below;

Create a Table:

Add rows:

Now this table has data like below;

Count not null values

There are total 14 not null values in all the columns and 22 NULL values in all columns. And below we are trying to get this … More

The post Count of total not null values from all columns of a table appeared first on SQLRelease.

http://www.sqlrelease.com/count-of-total-not-null-values-from-all-columns-of-a-table/feed 2
sp_executesql vs execute in SQL Server http://www.sqlrelease.com/sp_executesql-vs-execute-in-sql-server http://www.sqlrelease.com/sp_executesql-vs-execute-in-sql-server#comments Thu, 25 Dec 2014 07:46:08 +0000 http://www.sqlrelease.com/?p=277 In this post “SP_EXECUTESQL vs Execute”, we are going to compare sp_executesql and execute in SQL Server. Apart from differences, we will also discuss the similarities between sp_executesql and execute commands. Lets start with few questions like, What is the difference between Execute and sp_ExecuteSQL? How can we execute a T-SQL String? Similarities between Execute and sp_ExecuteSQL. Execute and sp_ExecuteSQL common features. Benefits of sp_ExecuteSQL. Which is better to use sp_ExecuteSQL or EXEC? Execute vs sp_ExecuteSQL.

Let’s discuss these points one by one.

Difference between sp_ExecuteSQL vs Execute


sp_ExecuteSQL is also used to execute a T-SQL string in SQL Server and points are below:

  • It allows parametrization and hence more secure than EXEC command to execute a SQL string dynamically. It’s tough to inject.
  • We don’t need to cast the parameter values as like we need in EXEC command. We simply put the parameter name in T-SQL string as


The post sp_executesql vs execute in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/sp_executesql-vs-execute-in-sql-server/feed 4
Convert date range into date list in SQL Server http://www.sqlrelease.com/convert-date-range-into-date-list-in-sql-server http://www.sqlrelease.com/convert-date-range-into-date-list-in-sql-server#comments Fri, 19 Dec 2014 07:30:33 +0000 http://www.sqlrelease.com/?p=271 In this post “Convert date range in date list”, we will convert a given date of range into list of dates as per the business requirement. Just have a look on mentioned demo table which has three columns CustomerID, StartDate and EndDate. I want to generate the date list for the given date range for each customer. For example if we have a entry as CustomerID – “1”, StartDate – “10-Dec-2012” and EndDate – “19-Mar-2013”, then this should return a date list for CustomerID 1 with 4 rows. First row for 10-Dec-12 to 31-Dec-12, Second row for 01-Jan-13 to 31-Jan-13, Third row for 01-Feb-13 to 28-Feb-13 and fourth row for 01-Mar-13 to 19-Mar-13.

Mind that in first row i have started with the actual start date of the given date range and in the last row i have put the end date as actual end date. But if there is … More

The post Convert date range into date list in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/convert-date-range-into-date-list-in-sql-server/feed 3
Truncate vs Delete in SQL Server http://www.sqlrelease.com/truncate-vs-delete-in-sql-server http://www.sqlrelease.com/truncate-vs-delete-in-sql-server#respond Thu, 18 Dec 2014 07:20:47 +0000 http://www.sqlrelease.com/?p=269 Difference between DELETE and TRUNCATE in SQL Server

Let’s discuss this point “Truncate vs Delete” below in simple way.

  1. Delete is a DML statement whereas Truncate is a DDL statement.
  2. Delete commmand deletes each row from the table which are satisfying the WHERE clause and logs it in the log file where as Truncate command deallocates the data pages and logs it in the log file.
  3. Delete performs slower than truncate because of logging mechanism it has whereas Truncate is faster than delete.
  4. Delete can remove full or partial data as per it’s filter defined in WHERE clause whereas Truncate does not support WHERE clause and all data will be removed from table.
  5. Delete executes the Triggers on the table if it has any because it is a DML command whereas Truncate does not execute the Triggers.
  6. Delete requires more locks than truncate because each row is locked for deletion


The post Truncate vs Delete in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/truncate-vs-delete-in-sql-server/feed 0
Full Text Search on files in SQL Server http://www.sqlrelease.com/full-text-search-on-files-in-sql-server http://www.sqlrelease.com/full-text-search-on-files-in-sql-server#respond Sat, 13 Dec 2014 19:27:35 +0000 http://www.sqlrelease.com/?p=256 What is Full Text Search in SQL Server?

Full Text Search in SQL Server enables us to perform complex queries against character based data. Full Text Search supports char, varchar, nchar, nvarchar, text, ntext, image, varbinary and xml data types. We Can store document files in varbinary(max) format with their extensions and enable Full-Text search on it. SQL Server supports many types of document files for Full-Text indexing some of them are .asp, .aspx, .ascx, .c, .doc, .html, .ppt, .txt, .xls and many more. Some other extension like .pdf provides it’s own “Filter Pack” to enable Full-Text index on pdf files in SQL Server.

To enable Full Text Search on one or more columns of the given table or indexed view, we have to create a Full Text Index on it. After creating a full text index, we can perform word searching or phrase searching on a column based on … More

The post Full Text Search on files in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/full-text-search-on-files-in-sql-server/feed 0
Fill Factor in SQL Server http://www.sqlrelease.com/fill-factor-in-sql-server http://www.sqlrelease.com/fill-factor-in-sql-server#respond Mon, 08 Dec 2014 19:05:52 +0000 http://www.sqlrelease.com/?p=253 Do you know what is FillFactor for an index? In this post, we will discuss about Fill Factor in SQL Server. Lets start discussion about FILLFACTOR in SQL Server.


Fill factor in SQL server is used to control the filled space of leaf pages with data. Remaining space is left to accommodate future growth of data inside the page. The default value for fill factor is 0 i.e. packed to 100%. Fill factor has a percentage value which could be anything between 1 and 100 including both. A page in SQL Server is the smallest unit of 8K, which holds the number of rows depending on the size of the row.

Setting Fill Factor

Fill factor can be set either at Server Level or at index level. Just see each in action below;

Setting Fill Factor at Server Level

By default it’s 0 at server level, but … More

The post Fill Factor in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/fill-factor-in-sql-server/feed 0
Creating primary key without clustered index http://www.sqlrelease.com/creating-primary-key-without-clustered-index http://www.sqlrelease.com/creating-primary-key-without-clustered-index#comments Wed, 03 Dec 2014 18:48:03 +0000 http://www.sqlrelease.com/?p=245 One of my colleague asked me a question that “Can we create a primary key without a clustered index?”. I answered him that “Yes, of-course!” and also did not forget to share this information to all of you in this post named “Create nonclustered primary key”. I know many of us are well aware of this and have did this many times in our day to day SQL activity. Still for those who don’t know how they can accommodate a primary key with a nonclustered index, i am sharing this post, in which i will show you that how we can create a non-clustered primary key on a table.

Before creating this nonclustered primary key, here i am showing you the default behavior of SQL Server during Primary key creation. In case table does not have any Clustered index created on it, SQL Server creates a PRIMARY KEY on a … More

The post Creating primary key without clustered index appeared first on SQLRelease.

http://www.sqlrelease.com/creating-primary-key-without-clustered-index/feed 3
Dynamic management views and functions in SQL Server http://www.sqlrelease.com/dynamic-management-views-and-functions-in-sql-server http://www.sqlrelease.com/dynamic-management-views-and-functions-in-sql-server#comments Mon, 01 Dec 2014 18:37:28 +0000 http://www.sqlrelease.com/?p=242 In this post named “Dynamic management objects in SQL Server”, we will explore the DMVs and DMFs in SQL Server. Dynamic management views (DMVs) and dynamic management functions (DMFs) are used to extract current internal information of the Server State using T-SQL commands. Formerly such types of data were only available in Performance Monitor (a Microsoft tool to analyze System performance), now SQL Server has exposed such information with some other important information related to current server state through dynamic management views and dynamic management functions. Both dynamic management views and dynamic management functions are collectively known as Dynamic Management Objects (DMOs). These objects were introduced primarily in SQL Server 2005 which allow us to monitor the current internal status of SQL Server using simple T-SQL.

DMVs and DMFs are very useful in collecting current performance related data of the system. We can categorize these objects in two groups as … More

The post Dynamic management views and functions in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/dynamic-management-views-and-functions-in-sql-server/feed 1
Open SQL Server Management Studio as different windows user http://www.sqlrelease.com/open-sql-server-management-studio-as-different-windows-user http://www.sqlrelease.com/open-sql-server-management-studio-as-different-windows-user#comments Mon, 24 Nov 2014 18:27:28 +0000 http://www.sqlrelease.com/?p=230 Have you ever required to open SQL Server Management Studio Application (SSMS instance) as different windows user from your local machine? Sometimes we require to “Run SSMS instance as different Windows user” another machine which is not available physically to us. In such type of scenarios we can open our local SSMS instance as different windows user at our local machine. In this article we are going to learn how we can open SSMS instance as different windows user. If you are still not required this till now, may be sometime in future you will be required to do the same.

Now to accomplish this task i.e. to open SSMS as a different windows user, we have below approaches;

  1. Using Run as different user option in windows explorer
  2. Using runas command in command prompt
  3. Using runas command with “.bat” file

We will cover all the above techniques below.

1. Using


The post Open SQL Server Management Studio as different windows user appeared first on SQLRelease.

http://www.sqlrelease.com/open-sql-server-management-studio-as-different-windows-user/feed 1
Deterministic and non-deterministic functions in SQL Server http://www.sqlrelease.com/deterministic-and-non-deterministic-functions-in-sql-server http://www.sqlrelease.com/deterministic-and-non-deterministic-functions-in-sql-server#comments Tue, 18 Nov 2014 18:08:52 +0000 http://www.sqlrelease.com/?p=228 In this topic “Deterministic and non-deterministic functions”, we are going to discuss the deterministic and non-deterministic functions in sql server. Lets start with “what is a deterministic function in sql server?”. It’s a common interview question also. I will elaborate the definition of deterministic as well as non-deterministic functions and also provide some good examples. So after reading this article you will be able to distinguish deterministic and non-deterministic functions.

Deterministic Functions

The functions which always return same output when they called with a particular set of input values in the same state of the database are known as deterministic functions.

Above t-sql code will always return the output as ‘ABCDEF’ and thus ISNULL is a deterministic function. Below is the list of some other deterministic functions.


Non-deterministic Functions

The functions which may return different result sets … More

The post Deterministic and non-deterministic functions in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/deterministic-and-non-deterministic-functions-in-sql-server/feed 7
Finding dependencies of a table in sql server http://www.sqlrelease.com/finding-dependencies-of-a-table-in-sql-server http://www.sqlrelease.com/finding-dependencies-of-a-table-in-sql-server#respond Sun, 16 Nov 2014 17:57:47 +0000 http://www.sqlrelease.com/?p=224 Many a times we face the problem of finding the foreign key relationships, triggers and stored procedures that are referring to a particular table. The below query will help you in identifying the following things:

  1. Find the entire hierarchy of all the parent tables and the corresponding parent table column names and their respective child(s).
  2. Find the entire hierarchy of all the child tables and the corresponding child table column names and their respective parent(s).
  3. The name of the triggers the table is referring to.
  4. The name of the stored proc which uses the table.

Let me elaborate this with the help of an example to have better understanding.

Let’s say I have created 3 tables as follows:

After that I have created the following stored procedure:

Now I will execute the procedure with following parameters:

1) Child1 as parameter


If I will execute the same stored proc with … More

The post Finding dependencies of a table in sql server appeared first on SQLRelease.

http://www.sqlrelease.com/finding-dependencies-of-a-table-in-sql-server/feed 0
Tracing deadlock with Extended events http://www.sqlrelease.com/tracing-deadlock-with-extended-events http://www.sqlrelease.com/tracing-deadlock-with-extended-events#respond Fri, 14 Nov 2014 16:54:23 +0000 http://www.sqlrelease.com/?p=214 In last two articles, we have learned how to capture deadlock using SQL Server Profiler and Tracing deadlock with Trace Flag 1222 and Trace Flag 1204. Now in this post we are going to learn a very useful method of tracing deadlock with Extended Events. These events are less resource intensive and light weight in comparison of SQL Server Profiler. We use these events to capture interested information to be analyzed now or later from heavy load servers (Like production server).

If we don’t have any clue about deadlock being occurred in midnight at our production server and because of heavy load on server, we can not use SQL Server Profiler their. Extended events are very useful because of very few resource utilization. We can create a session and start it to capture only those events in which we are interested. Extended events are very useful in such types … More

The post Tracing deadlock with Extended events appeared first on SQLRelease.

http://www.sqlrelease.com/tracing-deadlock-with-extended-events/feed 0
Tracing deadlock with Trace Flag 1222 and Trace Flag 1204 http://www.sqlrelease.com/tracing-deadlock-with-trace-flag-1222-and-trace-flag-1204 http://www.sqlrelease.com/tracing-deadlock-with-trace-flag-1222-and-trace-flag-1204#respond Thu, 13 Nov 2014 16:17:58 +0000 http://www.sqlrelease.com/?p=207 In previous article, we have already learned that how we can trace a deadlock situation with SQL Server Profiler. In case you don’t read, click here. And to understand locking, blocking and deadlocking in sql server, click here. In this post we will learn how we can use “trace flag 1204 and trace flag 1222” to trace a deadlock.

In this article we are going to learn how we can trace SQL Server deadlock and extract the deadlock information from captured data. We will use DBCC TRACEON command, Trace Flag 1204 and Trace Flag 1222 to capture the details.

What is DBCC (Database Console Commands)?

DBCC statements act as Database Console Commands for SQL Server. We can run it using TSQL programming language. It provides commands related to various categories like Maintenance, Miscellaneous,  Informational and Validation.


As we know that Deadlock in SQL Server is a situation … More

The post Tracing deadlock with Trace Flag 1222 and Trace Flag 1204 appeared first on SQLRelease.

http://www.sqlrelease.com/tracing-deadlock-with-trace-flag-1222-and-trace-flag-1204/feed 0
Tracing deadlock with sql profiler http://www.sqlrelease.com/tracing-deadlock-with-sql-profiler http://www.sqlrelease.com/tracing-deadlock-with-sql-profiler#comments Tue, 11 Nov 2014 11:59:14 +0000 http://www.sqlrelease.com/?p=200 Hi folks, In this article “Trace deadlock sql profiler”, we are going to learn, how we can capture a deadlock in a graphical form in sql server using an inbuilt tool of sql server named “SQL Server Profiler”.

First of all note that, don’t try to reproduce this sample deadlock and start SQL Server Profiler trace on your production server unless you are well versed of Profiler and event tracing. I recommend to do all these stuffs on you local machine to learn capturing deadlocks using SQL Server Profiler.

We are going to cover below points in this article;

  1. What is a deadlock?
  2. How to create a demo purpose deadlock?
  3. Using SQL Server Profiler to capture deadlock details and graphs.
  4. Understanding the deadlock important events in sql server profiler.

What is a deadlock?

A short note on deadlock:

Deadlock occurs when two sessions are waiting for a lock to clear … More

The post Tracing deadlock with sql profiler appeared first on SQLRelease.

http://www.sqlrelease.com/tracing-deadlock-with-sql-profiler/feed 3
Get total number of rows for all tables http://www.sqlrelease.com/get-total-number-of-rows-for-all-tables http://www.sqlrelease.com/get-total-number-of-rows-for-all-tables#respond Fri, 07 Nov 2014 11:44:11 +0000 http://www.sqlrelease.com/?p=196 How to get total number of rows for all the tables in a particular database? In this post we are going to learn how we can get “total number of rows for all tables” in a database.

We will use the inbuilt system views of SQL Server to generate this list. Sometimes we need to pick some high record containing tables for some demo or any other purpose.
To get the desired output, first select the database for which you want to extract the list of tables with total number of rows as below;


Now use the below query and have a look on its output;


Output :

total number of rows for all tables

From above output, you can see that we have extracted the list of all the tables for a particular database with total number of rows.

Analyze the used query above

In above query, I have used the inbuilt view SYS.Tables … More

The post Get total number of rows for all tables appeared first on SQLRelease.

http://www.sqlrelease.com/get-total-number-of-rows-for-all-tables/feed 0
SET XACT_ABORT in SQL Server http://www.sqlrelease.com/set-xact_abort-in-sql-server http://www.sqlrelease.com/set-xact_abort-in-sql-server#comments Thu, 06 Nov 2014 11:31:21 +0000 http://www.sqlrelease.com/?p=192 What is SET XACT_ABORT in SQL Server?

In this post “SET XACT_ABORT in SQL Server”, we will discuss about the XACT_ABORT command. SET XACT_ABORT controls the atomicity of any user defined transaction. By default SET XACT_ABORT is OFF. It specifies whether SQL Server automatically rollback and abort a transaction if any error occurred in any statement of the transaction. If SET XACT_ABORT is ON, if any run time error occur in any t-sql statement of the transaction, entire transaction is terminated and rolled back. If SET XACT_ABORT is OFF, only that statement which raised the error is rolled back and transaction continues the processing of other statements.

Note that if the severity of the error is high, entire transaction can be rolled back even if SET XACT_ABORT is OFF.


Scope of XACT_ABORT is at connection level and remains until either reconfigured or connection is closed. Note that … More

The post SET XACT_ABORT in SQL Server appeared first on SQLRelease.

http://www.sqlrelease.com/set-xact_abort-in-sql-server/feed 2
Locking, Blocking and Deadlocking in sql server http://www.sqlrelease.com/locking-blocking-and-deadlocking-in-sql-server http://www.sqlrelease.com/locking-blocking-and-deadlocking-in-sql-server#comments Tue, 04 Nov 2014 11:14:56 +0000 http://www.sqlrelease.com/?p=189 Lock vs Block vs Deadlock

Have you ever asked to differentiate lock, block and deadlock in sql server during your interview session? In this article we are going to differentiate these frequently confused terms – Lock, Block and Deadlock. So lets have a look on “Lock vs Block vs Deadlock”

These terms sound the same but are different in their meanings. Have a look on below definition to understand it.


When any session needs access to a piece of data from Database, a lock of some type is placed on that data to maintain the isolation property of database. Locking is different from blocking.


When a session needs to wait for a resource being locked by another session, this process is called as blocking. e.g. If session “A” is waiting for a resource “R” being used by session “B”, you can say that session “B” is blocking session … More

The post Locking, Blocking and Deadlocking in sql server appeared first on SQLRelease.

http://www.sqlrelease.com/locking-blocking-and-deadlocking-in-sql-server/feed 2
Apply vs Join in sql server http://www.sqlrelease.com/apply-vs-join-in-sql-server http://www.sqlrelease.com/apply-vs-join-in-sql-server#comments Fri, 24 Oct 2014 11:05:59 +0000 http://www.sqlrelease.com/?p=183 What is Apply in SQL Server?

In this topic “Apply vs Join”, we will discuss about the APPLY operator and its usage scenarios. Lot of people got confused “where they can use Apply and what is it”. They afraid about the performance and usage scenario also. In this article we are going to remove all these scary images of Apply from your mind.

So let’s start with ABCD of Apply and try to cover some advanced topics.

The primary use of Apply operator in sql server is to invoke a table valued function (TVF) but it can also be used in some other important scenarios. We will discuss the importance of Apply operator in brief in this article and would also compare this with Join operator. Invoking table valued function (TVF) is for what Microsoft introduced Cross Apply and Outer Apply primarily, as per MSDN.

Apply Operator executes for each … More

The post Apply vs Join in sql server appeared first on SQLRelease.

http://www.sqlrelease.com/apply-vs-join-in-sql-server/feed 3