Custom actions

functional

Turn your own SQL templates into right-click actions on tables, views, and routines.

Turn any of your own SQL templates into a right-click command on tables, views, procedures, and functions. Open Tools › Template Explorer, create or edit a template in My Templates, and tick Show in explorer right-click menu (Custom Actions). Pick which object kinds get it (all four by default; at least one must stay ticked). After that, right-clicking a matching object in the Object Explorer shows the template under Custom Actions. Materialized views don't get custom actions.

SQLly
A table's right-click menu with the Custom Actions submenu listing two user templates.
A table's right-click menu with the Custom Actions submenu listing two user templates.

Placeholders

SQLly fills these placeholders from the object you right-clicked before it opens the script. Names are written as quoted identifiers in the dialect of the connection the script opens on ([Orders] on SQL Server, "Orders" on PostgreSQL, `Orders` on MySQL), so names with spaces, reserved words, or quote characters stay one identifier and can't turn into extra SQL.

PlaceholderBecomes
{server}The connection's display name, as the explorer shows it, quoted as an identifier.
{database}The database the object lives in, quoted.
{schema}The object's schema, quoted (empty on engines without schemas).
{object}The object's own name, quoted.
{kind}table, view, procedure, or function.

Each of {server}, {database}, {schema}, and {object} has two other forms:

  • {object:literal} writes the name as a complete, escaped string literal in the connection's dialect, quotes included (N'Orders' on SQL Server, 'Orders' elsewhere). Use it wherever a function expects the name as text, for example OBJECT_ID({object:literal}).
  • {object:raw} writes the bare name with no quoting or escaping; only line breaks are turned into spaces. It's meant for comments and labels. Don't put it inside SQL or inside your own quotes, because a name containing a quote character would break out.

Each placeholder is replaced exactly once. A name that happens to contain placeholder text, such as {schema} or <n,int,5>, is written as-is and never expanded again. Braces that don't match one of these placeholders, such as JSON in a string, are left alone.

SSMS-style <name,type,default> parameters still work in the same template. When a template has any, clicking its custom action first opens a small Parameters dialog with one box per parameter, filled in with its default. Change what you need and press Script (or Run for a run action) or Enter; Cancel or Esc does nothing. As in SSMS, what you type replaces every copy of that placeholder exactly as written, with no quoting, so a value can be a number, a name, or a whole condition. A template without parameters skips the dialog. A template like this one lists the top rows of whatever table you right-click:

-- {kind} {object:raw} on {server:raw}
SELECT TOP <top_n,int,100> * FROM {schema}.{object};

Script or run

By default a custom action scripts: the filled-in SQL opens in a new query tab on the object's own connection and database, for you to review. To skip the review, tick Run immediately on the template. Those actions show (run) after their name in the menu.

A run action executes straight away only when its SQL, after your parameter values are filled in, is read-only (only SELECT statements, with nothing the engine's read-only check flags). Anything else, such as an UPDATE, a DROP, or a procedure call, opens the tab and shows the SQL in the confirmation dialog first, whether or not mutation review is turned on for the connection. Every normal execution safeguard still applies on top of that, including SELECT-only connections, the production lock, and tenant scoping.

SQLly looks the template up by name when you click (and again when you confirm its parameters), so an edit you save in Template Explorer takes effect straight away. Deleting a template removes its menu entry. SQLly keeps your templates in memory and watches the template file, so a change made to the file outside SQLly shows up in the menu a moment after it's saved. If the saved template file can't be read, Custom Actions lists nothing, running an action stops with a status-bar message, and Template Explorer names the problem instead of overwriting the file.