SQL Server: kill all database connections

| category: My notes | author: st
Tags:

How to kill all database connections before dropping it?

USE master;
GO
DECLARE @sql nvarchar(max);
WHILE 1=1 BEGIN
    SELECT TOP 1 @sql = N'KILL ' + convert(nvarchar(10), spid)
    FROM sysprocesses WHERE dbid = DB_ID('my_database');
    IF @@rowcount = 0  BREAK;
    EXEC sp_executesql @sql;
END;
DROP DATABASE IF EXISTS my_database;

C++11 constructors

| category: Programming | author: st
Tags: ,

According to specification, "...constructor is a special non-static member function of a class that is used to initialize objects of its class type". In addition to basic concepts, C++11 introduces move constructors, initializer list type and brace-enclosed lists of comma-separated initializers.

However the impact of introducing new constructors combining …

C++11 containers: move semantic vs pointers

| category: Testing | author: st
Tags: ,

Motivation

C++11 has introduced the move semantic which can also be used in containers instead of "old-school" pointers. The specific containers owning objects has been proposed earlier by third-party libraries like Boost (for example, ptr_map or ptr_vector).

The goal of the test is to compare the speed of manipulations …

SQL Server: temporary tables and constraint names

| category: Programming | author: st
Tags:

Update. Since the version 2016 SQL Server supports anonymous constraint declaration:

CREATE TABLE #temp_table (
   id1 int NOT NULL,
   id2 int NOT NULL,
   name1 nvarchar(100),
   name2 nvarchar(100),
   PRIMARY KEY (id1, id2),
   UNIQUE (name1, name2)
);

For earlier versions the solution is below.

Local temporary tables are isolated in the scope …