How to View Custom SQL Query in Tableau
Seeing the exact SQL query Tableau sends to your database can feel like a superpower. It transforms you from a dashboard creator into a data detective, empowering you to debug issues, optimize performance, and truly understand how your visualizations are being built. This guide will walk you through several methods to view this underlying SQL, turning a black box into a clear-and-simple process.
Why Bother Viewing the SQL in Tableau?
Before diving into the "how," let's quickly cover the "why." Understanding the SQL Tableau generates is more than just an academic exercise, it's a practical skill that helps you solve real-world problems.
- Debugging and Validation: Is your chart showing unexpected numbers? The most definitive way to find out why is to examine the query itself. You can see precisely which tables are being joined, what filters are being applied, and how data is being aggregated, helping you spot discrepancies between what you intended and what the database is doing.
- Performance Optimization: If a dashboard is slow, the culprit is almost always an inefficient query. By viewing the SQL, you can identify performance bottlenecks. Does the query have overly complex joins? Are filters being applied in the wrong order? Seeing the code allows you to tune your dashboard for speed, sometimes in collaboration with a database administrator.
- Deepen Your Understanding: For those on the journey to data mastery, viewing the generated SQL is an incredible learning tool. You can see how your drag-and-drop actions on the Tableau canvas translate directly into complex queries, demystifying the process and accelerating your data literacy.
- Testing and Reusability: Sometimes you need to grab the query to run it directly against your database for testing or reuse it in another application or script. Having direct access to the SQL makes your analysis portable.
Method 1: Using the Edit Custom SQL Query Option
Let's start with the most straightforward scenario. If you began your data connection in Tableau by writing a custom SQL query in the first place, viewing that original script is incredibly simple.
This method allows you to review and modify the base query you provided to Tableau. It's perfect for when you need to remember the initial logic you used or make a quick adjustment.
Free PDF Guide
AI for Data Analysis Crash Course
Learn how to get AI to do data analysis for you — the best tools, prompts, and workflows to go from raw data to insights without writing a single line of code.
How to Do It:
- Navigate to the Data Source tab in the bottom-left corner of your Tableau Desktop window.
- In the canvas area at the top of the screen, you will see your Custom SQL object represented as a single table.
- Hover over the Custom SQL object, click the drop-down arrow that appears, and select Edit Custom SQL Query...
- A dialog box will pop up, displaying your original SQL script. From here, you can view, copy, or edit it as needed.
When This Method Has Limits
This is a critical point: this method only shows you the starting query you wrote. It does not show how Tableau modifies or builds upon that query when you drag new fields onto your canvas, apply filters, or use parameters in a worksheet. For that, you need more advanced techniques.
Method 2: Tableau's Built-In Performance Recorder
The Performance Recorder is the best built-in tool for capturing the exact queries Tableau generates as you interact with your worksheets and dashboards. It's designed specifically for diagnosing slow-loading vizzes and is the cleanest way to see your SQL without digging through text files.
How to Do It:
- With your Tableau workbook open, go to the top menu and click Help → Settings and Performance → Start Performance Recording.
- Now, perform the exact action you want to analyze. This could be refreshing a data source, changing a filter, or simply loading a complex worksheet that's performing poorly.
- Once the action is complete, return to the menu and click Help → Settings and Performance → Stop Performance Recording.
- Tableau will immediately open a new workbook named "[PerformanceRecording]" that contains a pre-built dashboard analyzing the actions you just took.
- On the performance dashboard, look at the timeline. Click on an "Executing Query" bar (these are typically green) that corresponds to your interaction.
- In the bottom section, a "Query" text box will appear, displaying the full SQL query that was sent to your data source. You can copy this text directly from the box.
When to Use the Performance Recorder
This method is fantastic for isolating specific queries tied to user interactions. If you have a filter that's causing your dashboard to hang for 10 seconds, the Performance Recorder will capture the exact query that's causing the delay.
Method 3: Taking a Look at Tableau Log Files
If you need an even more comprehensive view of every single command Tableau is sending, the raw log files are your destination. This method is more technical and requires a bit of patience, but it provides a complete, unfiltered look at the communication between Tableau and your database.
Where to Find Your Log Files
Tableau Desktop creates log files for each session. You can typically find them in your Tableau Repository directory:
[Documents]\My Tableau Repository\LogsThe most relevant files are often log.txt and tabprotosrv.txt. The log.txt file contains information about what Tableau is doing, while tabprotosrv.txt logs the queries sent to the data source.
How to Capture a Clean Query:
- For the best results, start with a clean slate. Close all instances of Tableau Desktop.
- Navigate to your
Logsdirectory and move or delete the existing files. This prevents confusion. - Open Tableau Desktop and the specific workbook you want to investigate.
- Perform the action (e.g., refresh a view) that generates the query you need to see.
- Close Tableau Desktop. This ensures the session log is completely written.
- Go back to your
Logsfolder. Open thetabprotosrv.txtorlog.txtfile with a text editor like Notepad++, VS Code, or even just Notepad. - Use your editor's search function (Ctrl+F) to find your query. Search for keywords like
SELECT, a specific table name, or a column name you know is in your query. You will often find the query wrapped in XML-like tags, such as<begin-query>and<end-query>.
The logs are extremely verbose, so this takes some practice. But if you need an exhaustive record of activity, this is the most powerful method available directly in Tableau Desktop.
Tips for Managing SQL and Performance
Viewing SQL is great, but acting on what you find is what matters. Here are a couple of best practices for working with SQL queries in Tableau.
- Materialize Complex Logic in Your Database: If you find yourself writing a long, complicated Custom SQL query with multiple joins and transformations, consider saving this logic as a View or Materialized View directly in your database. Then, Tableau can connect to that simplified and pre-optimized view. This offloads the heavy processing to the database, where it belongs, and cleans up your Tableau data source model.
- Use Parameters in Custom SQL for Dynamic Filtering: Instead of hardcoding values, you can make your Custom SQL interactive by inserting Tableau Parameters. This allows users to change a filter on the dashboard, and the value will be passed directly into your SQL query.
Free PDF Guide
AI for Data Analysis Crash Course
Learn how to get AI to do data analysis for you — the best tools, prompts, and workflows to go from raw data to insights without writing a single line of code.
Example:
SELECT
*
FROM
public.orders
WHERE
region = <Parameters.Region Parameter>And just like that, a drop-down filter in Tableau can dynamically update your query without any complex workarounds.
Final Thoughts
Learning to view the underlying SQL in Tableau will elevate you from a tool user to a data professional. The Performance Recorder offers a user-friendly way to examine queries tied to actions, the log files provide an exhaustive record for deep troubleshooting, and the "Edit Custom SQL" dialog lets you quickly reference your original script. Using these methods will help you build faster, more accurate, and more reliable dashboards every time.
Of course, digging through logs and deciphering SQL highlights an inherent challenge in traditional data analysis - it wasn't built for teams that move fast and need answers now. We created Graphed to short-circuit this entire process. Instead of building vizzes and then digging for queries to debug them, you can simply connect your marketing and sales data sources and ask questions in plain English. Graphed automatically handles the query generation and builds live dashboards in real-time, giving you the insights without ever forcing you to become a database detective.
Related Articles
Facebook Ads for Home Cleaners: The Complete 2026 Strategy Guide
Learn how to run Facebook ads for home cleaners in 2026. Discover the best ad formats, targeting strategies, and budgeting tips to generate more leads.
Facebook Ads for Pet Grooming: The Complete 2026 Strategy Guide
Learn how to run Facebook ads for pet grooming businesses in 2025. Discover AI-powered creative scaling, pain point discovery strategies, and the new customer offer that works.
AI Marketing Apps: The 15 Best Tools to Scale Your Marketing in 2026
Discover the 15 best AI marketing apps in 2026, from content creation to workflow automation, organized by category with pricing and use cases.