T-SQL

Drop SQL Server stored procedures without errors

How to drop a SQL Server stored procedure without error using the existence check? To drop a SQL Server stored procedure and avoid errors, first test the existence of the procedure in the SQL Server database to condition the DROP PROCEDURE command. On the other hand, it is a good practice to always test the existence of SQL Server objects. In this case a

T-SQL

Store a SQL Server column in a variable with delimiters

Query to store the contents of a SQL Server column in a variable, inline and with delimiters. SQL tutorial to read and store the result from a SQL Server column in a variable, and with separators. In some cases, it is useful to get all the values of a column in a T-SQL variable and add a delimiter. How to store the contents of

T-SQL

Format a SQL query automatically and for free

How to format a SQL query automatically with a free online service? Format a SQL query automatically can be time-consuming and tedious, especially on existing projects that are not developed according to the rules of the art. There is a useful website that allows you to format SQL queries. Indeed, it is aimed at SQL development engineers, DBAs, and in general all SQL developers.

T-SQL

SQL Server SELECT queries to select and filter data

Example queries with the SQL Server SELECT function to select, filter and display data. T-SQL tutorial to learn how to use the SQL Server select queries to display and filter data from a table. This is the basic query because SQL, for Structured Query Language, is primarily designed to query and display data from a table. The query is of the type DML for

T-SQL

Test and drop a SQL Server view if it exists in the database

How to test and then drop a SQL Server view, if it exists in the database? Here is how to test the existence and drop a SQL Server view with a T-SQL script. Use this script as an example to test the existence of the view before deleting it. The goal is to not generate an error during the execution of a deployment script

T-SQL

T-SQL procedure with hard coded variables and dynamic execution

How to execute a T-SQL procedure from a text with a hard coded variable? Tutorial to manage and execute a T-SQL procedure with hard coded variables, i.e. stored in a string. Indeed, a normal execution does not work with the EXEC command alone. So how do you get around this error? The solution to the problem is to use the T-SQL EXEC function sp_executesql.

T-SQL

Calculate the difference between two dates with SQL Server

Calculate the difference between two dates in hours, minutes, and seconds with SQL Server functions. With the SQL Server time function DATEDIFF, it is possible to calculate the difference between two dates in hours, minutes, and seconds but only in one unit at a time. For example, only seconds, or only minutes or only hours. This SQL Server script uses the DATEDIFF function and

T-SQL

Create a temporary table with SQL Server

How to create and manage temporary tables with SQL Server? What is a SQL Server temporary table? SQL Server temp tables are temporary tables that are used for storing data temporarily. They are created with the CREATE TABLE command in T-SQL. In MS SQL tutorial, we will learn about SQL Server temp tables and what they are used for. There are two types of

T-SQL

Drop an index in SQL Server with a script

Another IT and more specifically a database tutorial on how to drop an index from a table in SQL Server. An index is associated with an existing table in a database. It can be a relational or transactional database. For example, learn here why it is important to implement maintenance plans to improve performance and management of MS SQL resources. Drop an index in

T-SQL

Reorganize a SQL Server index

How to reorganize a SQL Server index? This operation defragments the bottom level of the indexes by physically reordering the pages, from left to right. The reordering operation also compacts the pages of the index. To better understand this, imagine a recipe book whose pages are no longer in order. You must then reorganise the pages to quickly reach the desired page. Reorganize a