QueryScript is a scripting language for SQL

QueryScript is a programming language aimed for SQL scripting, seamlessly combining scripting power such as flow control & variables with standard SQL statements or RDBMS-specific commands.

common_schema implements QueryScript for MySQL: it provides the execution mechanism for QueryScript code (see Execution).

What does QueryScript look like? Here are a couple examples:

while (DELETE FROM world.Country WHERE Continent = 'Asia' LIMIT 10)
  throttle 2;
foreach($table, $schema, $engine: table in sakila)
  if ($engine = 'InnoDB')
    ALTER TABLE :$schema.:$table ENGINE=InnoDB ROW_FORMAT=Compact;

With QueryScript one can:

  • Use familiar syntax to solve common DBA maintenance problems
  • Loop through number sequences, constants, tables, schemata
  • Easily iterate query results, providing cursor-like functionality with clean syntax
  • Use conditional statements and statement blocks
  • Create and use variables
  • Expand variables in-place, turning them to constants in queries where variables are not allowed

QueryScript programs execute from within the server. As opposed to scripts written with Perl, Python or PHP, QueryScript code does not need to specify connections, logins nor passwords. There is no connector to install and use, there is no driver setup. There are no plugins.


run(), Execution, Statements


Shlomi Noach
common_schema documentation