There are a ton of great resources for getting help on the Internet from highly skilled professionals. However, asking “why doesn’t ‘xyz’ work?” without providing detail just wastes everyone’s time. This page provides a template for a Minimal, Complete, and Verifiable Example (MCVE) to use when asking database-related questions on StackExchange’s site for Database Administrators, dba.stackexchange.com.
Taking the time to formulate a great question by writing an MCVE serves several purposes:
- You think through the problem in detail, and may end up solving the problem without requiring anyone’s help. This is commonly called rubber ducking the problem.
- The example makes it clear where the problem is.
- Details you give to build-up the example help others quickly focus on the problem, not the fluff.
You’re far more likely to get great help from someone when they see you’ve taken the time to build a great question. It makes it more fun, and more fun equates to better and faster answers for you.
When constructing a question, add code and as many technical details as possible, but keep the following in mind:
- Keep the details to the bare minimum required to convey the question. Providing details about every table in your database when the question only concerns how to join 2 of them just creates clutter that is hard to cut-through.
- Include every detail you can about the real problem you’re attempting to resolve. Don’t create an abstract MCVE that is so far removed from the original problem that it will be difficult to translate the answers you get into the real work you’re doing.
- Unless your question is about a syntax error, make sure your code works without errors before submitting your question. This may seem a bit basic, but you’d be surprised how many times example code doesn’t actually run, or the output doesn’t match the “real” scenario.
On to the template. First up, we have a template for a simple query problem. They kind of thing where you need to combine some data from a couple of tables, but have no idea how to go about it. To use this in your own question, simply copy-and-paste it into a new question.
I'm having this problem getting these two tables combined into the desired output. The first table: ``` CREATE TABLE <table_name_1> ( column1 ... column2 ... ); ``` The second table: ``` CREATE TABLE <table_name_2> ( column3 ... column4 ... ); ``` Sample data for these two tables: ``` INSERT INTO <table_name_1> (column1, column2) VALUES (12, 34); INSERT INTO <table_name_2> (column3, column4) VALUES (56, 78); ``` I'm trying to get my output to look like this: <pre> ╔═════════╦═════════╗ ║ column1 ║ column2 ║ ╠═════════╬═════════╣ ║ 12 ║ 34 ║ ║ 56 ║ 78 ║ ╚═════════╩═════════╝ </pre> The query I have written is: ``` SELECT * FROM t1 CROSS JOIN t2 ``` <pre> ╔═════════╦═════════╦═════════╦═════════╗ ║ column1 ║ column2 ║ column3 ║ column4 ║ ╠═════════╬═════════╬═════════╬═════════╣ ║ 12 ║ 34 ║ 56 ║ 78 ║ ╚═════════╩═════════╩═════════╩═════════╝ </pre>
In the template above, I show query output in a nice ASCII box format. There are many places on the Internet that will convert output like that, but the one I find particularly useful since it works out-of-the-box for SQL Server Management Studio query results, is at https://ozh.github.io/ascii-tables/. Simply click the “copy with headers” menu item by right-clicking the results from an SSMS query into the webpage, like this:
Then past it into the https://ozh.github.io/ascii-tables/ webpage, like this:
Alternately, you could use the following sites that allow you to run query code in a sandbox environment. These sites are especially handy for questions-and-answers since they allow you to try various ways of making it work: