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.