-8

Now that we can finally use formatted tables in questions and answers, I suggest enhancing the feature to also optionally generate an SQL CREATE+INSERT script for each table in a question.

We can use the question tags as a trigger, where any question tagged sql would have an extra small link at the bottom of a table. Clicking the link would run JavaScript code to generate the SQL on the client, and either show the script or put it in the clipboard. Datatypes would either be inferred or always varchar (I'd much rather just change a few datatype declarations than type a whole script).

This would make it easier to answer questions for people by letting us more quickly set up testing and example tables on sites like SQL Fiddle, db<>fiddle, etc.

An advanced option or stretch goal would be smart enough to see tags like mysql or sql-server, and know the different variations in SQL syntax between the databases.

5
  • 2
    I suspect that the vast majority of table formatting usages wouldn't benefit from this change; it would be completely useless for tables on anything but questions tagged [sql] and related on Stack Overflow and only a small group of other sites.
    – zcoop98
    Commented Apr 29, 2022 at 16:21
  • @zcoop98 That's why I recommend the feature is scoped to the tag. Commented Apr 29, 2022 at 16:26
  • 2
    This seems like too much to ask for when they can't even keep the Javascript dependency versions up to date in Stack Snippets. (That's a feature which probably has a wider audience. How many people use a rigorously defined table format for their SQL? With the framework I work with, I would give out my migration file, which only works when using that framework.)
    – Laurel
    Commented Apr 29, 2022 at 16:46
  • 7
    This sounds like a great userscript project. I don't see the value of paying the cost of the additional JS for the majority of site visitors, however. Commented Apr 29, 2022 at 17:07
  • 1
    Are they some external services that already do this (not a rhetorical question)? Commented Apr 29, 2022 at 17:28

1 Answer 1

8

I am not sure if Stack Exchange will implement this feature request. I suggest you to use https://tableconvert.com/markdown-to-sql.

The website helps you to convert Markdown tables to SQL queries.

For example, this is my Markdown table:

What? When? Where?
Table support 2020-11-23 Meta Stack Exchange & DBA Meta
More table support week of 2020-11-30 DBA Stack Exchange
Even more table support week of 2020-12-07 Network-wide launch (if no major issues found)

The website gives us these queries:

CREATE TABLE tableName 
(
    What?   varchar(300),
    When?   varchar(300),
    Where?  varchar(300)
);

INSERT INTO tableName (What?,When?,Where?)
VALUES
    ('Table support', '2020-11-23', 'Meta Stack Exchange & DBA Meta'),
    ('More table support', 'week of 2020-11-30', 'DBA Stack Exchange'),
    ('Even more table support', 'week of 2020-12-07', 'Network-wide launch (if no major issues found)');
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .