How to create a Minimal, Complete, and Verifiable Example for database-related questions

Database-related questions asking for practical advice will get the most helpful answers if they provide a framework others can use to reproduce that problem.

With that in mind, when asking a question please create a framework that is:

  • Minimal – Use as little code as possible that still produces the same problem
  • Complete – Provide all parts needed to reproduce the problem
  • Verifiable – Test the code you're about to provide to make sure it reproduces the problem

Minimal

Reducing the code to the bare minimum necessary to convey the problem makes the question easier to ask, and inherently easier to answer. Win-win. If you have a question about a query that has 400 columns, and all 400 columns are not required for the answer, only show the two or three columns that are pertinent to the question.

Complete

Include all the tables, queries, indexes, constraints, and other parts as necessary to ensure the person answering your question has all the information at the outset. When including these pieces, provide the SQL scripts so others don't have to recreate them. Do not provide screenshots of tables or results. You can even use an online resource such as db<>fiddle or SQL Fiddle both of which support most major RDBMS platforms and allow you and others to run your example.

Verifiable

Include test output, in text formatted as a table, to show both what you're currently getting as well as what your desired output should be. Search for "ascii table generator" on your favorite search engine - there are several that are extremely easy to use.

An example question, including an MCVE framework

I want to get the total count of the number of ducks in each pond.

The ponds table:

CREATE TABLE ponds
(
      PondName varchar(30)
      , DuckName varchar(30)
);

Some sample data:

INSERT INTO ponds (PondName, DuckName)
VALUES ('Golden', 'Daffy')
     , ('Walden', 'Daisy');

My query so far:

SELECT COUNT(DuckName)
FROM ponds;

The output I'm getting:

╔═══════╗
║ Value ║
╠═══════╣
║     2 ║
╚═══════╝

The output I'd like to get:

╔════════╦═══════╗
║  Pond  ║ Count ║
╠════════╬═══════╣
║ Golden ║     1 ║
║ Walden ║     1 ║
╚════════╩═══════╝
  • 1
    Perhaps you should convert this to question and answer format? And put the answer in the answer box? I know it's not strictly necessary for Meta, but I think it would be better that way. – Wildcard Jun 1 at 10:00
  • @wildcard - see dba.meta.stackexchange.com/questions/2981/… – Max Vernon Jun 1 at 11:09
  • Who do we bribe to get this added as an official dba.se help page? – John Eisbrener Jul 25 at 15:41
  • Great question; it would be either a moderator or a community manager such as @Taryn – Max Vernon Jul 25 at 16:45

You must log in to answer this question.

Browse other questions tagged .