Etoiles inactivesEtoiles inactivesEtoiles inactivesEtoiles inactivesEtoiles inactives

Export data from SQL Server as fast as possible

Exporting large volumes of data from SQL Server is a common requirement for analytics, data migration, backups, or data sharing. However, not all export tools deliver the same performance, scalability, or ease of use.

In this article, we compare several common approaches using the TPC-H orders table as a benchmark:

  • BCP (CLI – native SQL Server tool)
  • SSIS (No-code ETL)
  • sqlcmd (CLI – scripting oriented)
  • FastBCP (CLI – high-performance parallel exporter)


Test context

We use the TPC-H orders table, typically containing millions of rows:


SELECT COUNT(*) FROM dbo.orders; ==> 15M Rows
 

Assumptions:

  • SQL Server 2019+
  • Export to CSV format
  • Local SSD storage
  • Minimal transformation (raw export)


1. BCP (Bulk Copy Program)

BCP is the historical command-line tool provided by Microsoft. It is fast, lightweight, and reliable, but limited to single-threaded exports.

BCP export command

  

bcp "SELECT * FROM dbo.orders_15M" `
queryout D:\temp\orders_bcp.csv `
-c `
-t ";" `
-r "\n" `
-S localhost `
-d tpch_test `
-T -u
 

Pros

  • Fast for single-threaded export
  • No additional dependencies
  • Stable and well-known

Cons

  • No parallelism
  • No Header :-(
  • Limited control over formatting
  • Limited log output or too long
  • No compression
  • No partitioning output
  • Export only locally
  • Export only CSV or SQL binary format
  • Only SQL Server

BCP MSSQL to CSV Local Command Results


2. SSIS (SQL Server Integration Services)

SSIS is a graphical ETL tool suitable for non-developers and complex pipelines. It can reach good performance but requires more setup and infrastructure.

Typical SSIS flow

  • OLE DB Source → orders table
  • Flat File Destination → CSV

Key performance settings:

  • Appropriate DefaultBufferMaxRows
  • Minimal transformations

Pros

  • No code required
  • Scheduling
  • Logging
  • Monitoring
  • Work for many databases
  • Can make complex transformations

Cons

  • No parallelism
  • Heavier infrastructure (service, database
  • Slow Dev
  • Slow to scale to hundreds of tables
  • Lower raw performance than CLI tools
  • Not ideal for simple exports
  • Export only locally

 

SSIS MSSQL to CSV 2025 12 29 01h26 23 SSIS and CSV columns definition  

 

SSIS MSSQL to CSV Results Time

 


3. sqlcmd

sqlcmd is a scripting-oriented CLI tool. It is flexible but not designed for high-volume exports.

sqlcmd export command


measure-command {sqlcmd -S localhost -d tpch_test -E `
-Q "SET NOCOUNT ON; SELECT * FROM dbo.orders_15M" ` -o D:\temp\orders_sqlcmd.csv ` -s ";" -W
}


  

Pros

  • Very simple
  • Good for automation scripts
  • No additional tooling

Cons

  • No parallelism
  • No Logs
  • Bad Header : need some trick to remove the 2nd line
  • Only work with SQL Server
  • Export only locally

sqlcmd csv export


4. FastBCP (High-performance parallel export)

FastBCP is a modern CLI tool designed specifically for maximum export speed. It uses parallel extraction to fully leverage modern CPUs and storage.

Official website: https://fastbcp.arpe.io

FastBCP export command


.\FastBCP.exe `
--connectiontype "mssql" `
--server "localhost" `
--database "tpch_test" `
--trusted `
--sourceschema "dbo" `
--sourcetable "orders_15M" `
--query "SELECT * FROM dbo.orders_15M" `
--directory "D:\Data\fastbcpexport\raw\{sourcedatabase}\{sourceschema}\" `
--fileoutput "{sourcetable}.csv" `
--decimalseparator "." `
--delimiter ";" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--method "RangeId" `
--distributekeycolumn "o_orderkey" `
--paralleldegree -2 `
--merge false

Key concepts

  • Table\Query can be splitted using a parallel method
  • Multiple concurrent readers
  • Linear scalability with CPU cores

Pros

  • Much faster than BCP, SSIS and sqlcmd
  • True parallelism
  • Simple CLI usage
  • Clean header without headacke
  • Drivers included
  • Templating for output files names and directories
  • Work on other databases (Oracle, MySQL, PostgreSQL, Netezza, ODBC...)
  • No installation (just copy the .exe file)
  • Works on windows and linux
  • Can also export to cloud (AWS S3, S3 compatibles, Azure (ABS & ADLS), GCS, OneLake)

Cons

  • External tool
  • Can be cpu intensive (but this is what you want to go faster)

FastBCP MSSQL to CSV Local Command

 

FastBCP MSSQL to CSV Local Results


Performance comparison (typical results)

ToolSpeedDev TimeParallelComplexityLimited to SQL Server
sqlcmd Slow (38s) Fast (30s) No Low

Yes

SSIS Slow (39s) Slow (10min) No High No
BCP fast (21s) Fast (30s) No Low Yes
FastBCP Very fast (3s) Fast (30s) Yes Low No


Conclusion

If you need a quick and simple export, BCP remains a solid choice. For complex ETL pipelines and workflows, SSIS is appropriate. For scripting, sqlcmd is convenient but some issue and limitated to SQL Server.

However, when the objective is exporting large SQL Server tables as fast as possible, FastBCP clearly stands out thanks to its parallel architecture and CLI simplicity. Bonus it can do the same for many other databases and format (parquet, json , xlsx)

 

Commentaire (0) Clics: 898

Vote utilisateur: 4 / 5

Etoiles activesEtoiles activesEtoiles activesEtoiles activesEtoiles inactives

Sans avoir besoin d'un RAC (Real Application Cluster), d'un grid ou d'un exadata, Oracle fourni en standard un mécanisme de parallelisme très poussé.

Le parallelisme peut se retrouver dans les requêtes de selection mais également dans les chargements de masse via SQL (create as select, insert into select,...)

Commençons par étudier la partie selection et les mécanismes internes d'Oracle qui permettent d'accélérer les traitements par utilisation du parallelisme.

Une requête select utilisera le parallelisme si:

  • Un ou plusieurs objets utilisés par la requête (Table, Index, Vues matérialisée...) ont été créés (ou altérés) avec l'option PARALLEL
  • Ou si la requête elle même contient un hint +PARALLEL(table dop) ou +PARALLEL_INDEX(index dop) avec dop un entier (optionnel) représentant le degré de parallelisme souhaité.
  • Dans tous les cas, si l'optimiseur considère que l'utilisation du parallelisme est bien pertinant pour la requête.

Le CBO (Cost Based Optimizer), est bien le décideur pour savoir si le recours au parallélisme est utile ou non. En fonction des valeurs en paramètre par exemple (toujours à conditions d'avoir de bonnes statistiques). L'optimiseur peut décider que pour une valeur particulière en  prédicat il est préférable de faire un table scan et dans ce cas, si la table à l'option PARALLEL ou un hint PARALLEL, le scan se fera en parallèle, alors que pour une autre valeur du même prédicat, l'utilisation d'un index est préférable et l'optimiseur peut choisir un autre plan pour cette valeur.

L'utilisation du parallelisme réduisant la plupart (voir toujours) le cout d'un scan, pour l'optimiseur, on croit à tort, que le hint /*+PARALLEL(t)* forcera le scan de la table en parallèle. Or c'est faux, il est possible et probable que l'optimiseur bascule vers se type de plan mais il reste maitre de modifier le plan s'il considère le scan comme non optimal.

Exemple :

 

Commentaire (0) Clics: 26331

Vote utilisateur: 5 / 5

Etoiles activesEtoiles activesEtoiles activesEtoiles activesEtoiles actives

Les traitements shells nécessitent souvent de tracer les compte-rendus dans un fichier de trace.

Voici deux petites fonctions très utiles qui permettront de le faire en choisissant votre niveau de trace ainsi qu'un exemple d'utilisation

 Le fichier Trace_Lib.sh -->

Vote utilisateur: 5 / 5

Etoiles activesEtoiles activesEtoiles activesEtoiles activesEtoiles actives

k-means clustering

k-means is a kind of clustering algorithms, which belong to the family of unsupervised machine learning models. It aims at finding $k$ groups of similar data (clusters) in an unlabeled multidimensional dataset.

The k-means minimization problem

Let $(x1, ..., xn)$ be a set of $n$ observations with $xi \in \mathbb{R}^{d}$, for $1 \leq i \leq n$. The aim of the k-means algorithms is to find a disjoint partition $S={S1, ..., Sk }$ of the $n$ observations into $k \leq n$ clusters, minimizing $D$ the within-cluster distance to center: $$ D(S) = \sum{i=1}^k \sum{x \in Si} \| x - \mui \|^2 $$ where $\mui$ is the $i$-th cluster center (i.e. the arithmetic mean of the cluster observations): $\mui = \frac{1}{|Si|} \sum{xj \in Si} xj$, for $1 \leq i \leq n$.

Unfortunately, finding the exact solution of this problem is very tough (NP-hard) and a local minimum is generally sought using a heuristic.

The algorithm

Here is a simple description of the algorithm taken from the book "Data Science from Scratch" by Joel Grus (O'Reilly):

  1. Start with a set of k-means, which are $k$ points in $d$-dimensional space.
  2. Assign each point to the mean to which it is closest.
  3. If no point’s assignment has changed, stop and keep the clusters.
  4. If some point’s assignment has changed, recompute the means and return to step 2.

This algorithm is an iterative refinement procedure. In his book "Python Data Science Handbook" (O'Reilly), Jake VanderPlas refers to this algorithm as kind of Expectation–Maximization (E–M). Since step 1 is the algorithm initialization and step 3 the stopping criteria, we can see that the algorithm consists in only two alternating steps:

step 2. is the Expectation:

"updating our expectation of which cluster each point belongs to".

step 4. is the Maximization:

"maximizing some fitness function that defines the location of the cluster centers".

This is described with more details in the following link.

An interesting geometrical interpretation is that step 2 corresponds to partitioning the observations according to the Voronoi diagram generated by the centers computed previously (either on step 1 or 4). This is also why the standard k-means algorithm is also called Lloyd's algorithm, which is a Voronoi iteration method for finding evenly spaced sets of points in subsets of Euclidean spaces.

Voronoi diagram

Let us have a look at the Voronoi diagram generated by the $k$ means.

As in Jake VanderPlas' book, we generate some fake observation data using scikit-learn 2-dimensional blobs, in order to easily plot them.

```python %matplotlib inline import matplotlib.pyplot as plt from sklearn.datasets.samplesgenerator import makeblobs

k = 20 n = 1000 X, _ = makeblobs(nsamples=n, centers=k, clusterstd=0.70, randomstate=0) plt.scatter(X[:, 0], X[:, 1], s=5); ```

png

Sous-catégories

Articles traitant de l'intégration de données

Des tutoriaux et cours gratuits sur Oracle

Tutoriaux sur Unix et les shells scripts