I am inserting about 400 rows into a table at a time (SQL Server 2008). I have tried UNION ALL, but that slowed things down considerably. I settled on the following query:
INSERT INTO table VALUES (a, b,...),(c, d,...),...(x,y,...);
When I make this query through ODBC it takes roughly 400ms (I use C++ and time the single call to sqlExecDirect going to odbc32.dll). However, when I run the query inside MS SQL Server Management Studio wrapped by Getdate():
SELECT Getdate()
INSERT INTO ...
SELECT Getdate()
it takes ~10ms. For comparison, on the same machine, the same query in MySQL takes roughly 20ms.
- Is SELECT Getdata() a reliable way to time a transaction?
- Why is MS SQL Server Management Studio so much faster?
- What can I do to improve the performance? Any alternatives to ODBC? Direct connect to SQL server?