Category Archives: Databases

How to import data from MySQL to SQL Server 2014 ?

Importing data from one database engine to another is often a pain. Getting the data out of MySQL is easy, but pushing it to SQL Server may be harder. The easiest way to achieve this is to use “SQL Server Import and Export Wizard” to directly query your MySQL Database, and push the data in your SQL Server.

Trying other techniques often leads to a waste of time. For example, Continue reading

How to execute the same SQL query on each database of a SQL Server instance ?

You want to execute the same SQL query on each database of your SQL Server. For example, because you have one database per customer and want to collect info about your customers’ databases version, size, etc.

The following T-SQL code illustrates how to get the number of tables in each database whose name starts with “RH”, and presents the result in one single recordset. Continue reading

How to kill all active connections to a SQL Server DB before a restore ?

You may have faced situations when you need to restore a SQL Server database, but the restoration fails because a connected user prevents SQL Server from acquiring the required exclusive mode.

The T-SQL script below will kill all active sessions by switching immediately to exclusive mode. you’ll then be able to restore the db (or perform any other operation requiring exclusive mode), before switching back to multi-user mode. Continue reading

How to clean SQL Server cache before performance testing ?

One of your customers reported some very slow Microsoft SQL Server database access times. You restored his database at home, and were able reproduce the performance issue. But after the first execution, your super-slow query is now blazing-fast. Still you didn’t make a change… This is a courtesy from the SQL Server performance engine which cached a lot of things related to your previous query execution. How can you clear/flush this SQL Server cache before executing your performance tests ?

Continue reading