SQL Server DB

Create a SQL Server database with a script

In order to create a new SQL Server database with one script, just follow this article and especially the code snippet. To create a Microsoft database with a Transact-SQL script, use the CREATE DATABASE function as explained in this post. First, a database represents the main part of a Relational Database Management System. An RDBMS contains and runs databases. A database contains SQL objects

SQL Server DB

Display SQL Server detailed version with a query

How to display the SQL Server detailed version number with a simple SQL Server query? Using SQL Server Management Studio, to get the exact version of the SQL Server installation, it is possible by using simple T-SQL queries. For example, it is very helpful to know the exact version of SQL Server installed. Especially when working on security patches and upgrades. But also, when


SQL Server text with more than 8000 characters

How to manage SQL Server text with more than 8000 characters without errors? VARCHAR and NVARCHAR fields are limited to 8000 characters with SQL Server. Handle text fields longer than 8000 characters and you get the following message: “The text, ntext, and image data types are invalid for local variables. Here is a solution to get around this 8000 character limitation in T-SQL with


Display the modification date of a SQL Server table

How to display the modification date of a SQL Server table? This sample SQL query uses SQL Server system tables to detect the latest changes made to a SQL Server table or view. It displays the creation date and the last update date. Moreover, this query only takes into account the tables because it reads the data from the system table sys.tables. How to

SQL Server error

Invalid object name SQL Server CTE Error

How to avoid the Invalid object name SQL Server CTE Error ? Or how to execute multiple SELECT queries on the same CTE ? As a reminder, a CTE is a temporary object that only exists between its creation and the first time it’s used. It means it’s deleted right after the first query ran against the CTE. Indeed when querying the second time


Display the full month name with SQL Server

How to display the full month name from a date with SQL Server ? Which is to say with the complete month names like January, February, March, April, May, etc. written out in full. This query shows you how to get the entire month names from the current date or any other date. Indeed, with a simple SELECT GETDATE() you can display easily the current


Implicit conversion from data type XML to NVARCHAR is not allowed error

How to convert XML into NVARCHAR with SQL Server? To avoid the SQL Server error conversion from XML to NVARCHAR. The exact message is “Implicit conversion from data type xml to nvarchar is not allowed. Use the CONVERT function to run this query.”. With SQL Server data, it is useful to combine numerical columns, alphanumeric strings and XML typed columns.   In addition, to


Violation of Unique Key constraint with SQL Server

How to avoid Violation of Unique Key constraint with SQL Server ? Insert or update data in an SQL Server table with a simple query? Here are two simple solutions to execute an update or insert and avoid errors. The SQL Server error ” Violation of UNIQUE KEY constraint . Cannot insert duplicate key in object . The duplicate key value is ” because

SQL Server error

Arithmetic overflow error converting expression

With SQL Server, how to avoid this error : “Arithmetic overflow error converting expression to data type int”. Let’s insert some data into a table using a stored procedure for example. Facing this SQL Server error message can be disturbing. Even if SQL conversion errors are classical ones, finding the solution and apply the industry best practices to avoid them is very useful. In

Excel Tips

How to pivot Excel rows into columns ?

How to pivot the rows of an Excel table into columns? It’s relatively simple. You just need to select the area you want to rotate, in our example it is an Excel table with financial amounts and months. On the other hand, the special paste of the copied data is the Excel option to rotate the rows into columns. How to pivot the rows