How to fix Error 5350 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 5350 — “CSV format supports only TABLESAMPLE PERCENT option”

Why This Error Happens

This error occurs when a query uses the TABLESAMPLE clause with the ROWS option while attempting to read from or export data to a CSV-formatted external data source, such as a CSV file accessed via PolyBase or an external table in SQL Server 2025. The CSV format’s underlying row-reading mechanism cannot guarantee a fixed physical row count sample because it processes data as a streamed, delimited text format rather than a fixed-page structure. As a result, SQL Server rejects any TABLESAMPLE syntax that isn’t expressed as a PERCENT value, since percentage-based sampling is the only method compatible with sequential text parsing.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Query

  • Review the T-SQL query or stored procedure that triggered Error 5350.
  • Search specifically for the TABLESAMPLE keyword followed by a numeric row count (e.g., TABLESAMPLE (1000 ROWS)).
  • Confirm the target table is an external table pointing to a CSV data source by running:
  SELECT name, location, data_source_id FROM sys.external_tables;

Step 2: Rewrite the Query to Use PERCENT Syntax

  • Replace the ROWS clause with an equivalent PERCENT value.
  • Example fix:
  -- Incorrect (causes Error 5350)
  SELECT * FROM dbo.ExternalCsvTable TABLESAMPLE (500 ROWS);

  -- Corrected
  SELECT * FROM dbo.ExternalCsvTable TABLESAMPLE (10 PERCENT);
  • If an approximate row count is required, calculate the percentage manually based on estimated total rows in the source file (e.g., 500 rows out of ~5,000 total ≈ 10 PERCENT).

Step 3: Validate External Data Source and File Format Settings

  • Open SQL Server Management Studio (SSMS) and check the external file format definition:
  SELECT * FROM sys.external_file_formats WHERE format_type = 'DELIMITEDTEXT';
  • Ensure the FORMAT_TYPE is correctly set to DELIMITEDTEXT (the internal type used for CSV) and not mistakenly mapped to a row-addressable format like PARQUET or ORC.
  • If the table was meant to use a different format that supports ROWS sampling, recreate the external table using PARQUET instead of DELIMITEDTEXT.

Step 4: Apply Latest Cumulative Update

  • On Windows Server 2025, open Settings > Windows Update and check for pending SQL Server 2025 Cumulative Updates (CUs), as early builds may have stricter or buggy TABLESAMPLE validation logic.
  • Alternatively, download the latest CU directly from the Microsoft Update Catalog and install via:
  Start-Process -FilePath "SQLServer2025-KB*****-x64.exe" -ArgumentList "/quiet /IAcceptSQLServerLicenseTerms"

Alternative or Verification Steps

  • Re-run the corrected query in SSMS or Azure Data Studio and confirm it executes without raising Error 5350; verify the returned row count approximates your expected sample size.
  • As an alternative, if row-exact sampling is a hard requirement, first import the CSV data into a standard SQL Server table (via BULK INSERT or OPENROWSET) and then apply TABLESAMPLE (N ROWS) on the native table instead of the external CSV source.