Lukla Data Studio Docs

Docs Editor

Writing queries

Completion that knows your schema, join suggestions from foreign keys, snippets, and the editing commands in the T-SQL editor.

On this page
  1. Completion
  2. Join suggestions
  3. Aliases
  4. Snippets
  5. Editing commands
  6. Navigating your code
  7. Links that open the editor

The editor reads your database's schema, so completion, checks and fixes are about your tables, not generic SQL.

A query on Northwind in the editor, with results below
A query tab: the connection and database are in the tab, the statement under the cursor is shaded.

#Completion

Completion appears as you type (⌃Space shows it any time) and knows the query around the cursor:

  • Tables after FROM and JOIN, with their schemas.
  • Columns with their types after an alias and a dot (cus.), and every column in scope elsewhere, qualified when two tables share a name.
  • CTE and derived-table columns, and declared variables.
  • Whole joins from foreign keys after JOIN, with the ON clause written and a meaningful alias.
  • * → the column list, INSERT INTO t → its column list and a VALUES template, and EXEC proc → named parameters with their types.

Tab or ↩ accepts a suggestion.

#Join suggestions

Type JOIN after a table and the suggestions are the tables it has foreign keys to, each with its ON clause:

T-SQL
SELECT soh.SalesOrderID, soh.TotalDue
FROM Sales.SalesOrderHeader soh
JOIN Sales.Customer cus ON cus.CustomerID = soh.CustomerID   -- picked from the list

After a join, the next JOIN suggests the tables the joined one leads to as well, so a chain such as Customers → Orders → Order Details is two picks:

Recorded in the app: two joins from the list, a run, and the sum of the selected cells in the status bar.

#Aliases

New aliases are meaningful rather than t1, t2: Customers becomes cus and SalesOrderHeader becomes soh. Choose your own per table in Settings ▸ Editor ▸ Table aliases.

#Snippets

Type a snippet's name and press Tab:

SnippetExpands to
ssfSELECT * FROM
s100SELECT TOP (100) * FROM
scfSELECT COUNT(*) FROM
iiINSERT INTO … VALUES
uuUPDATE … SET … WHERE
dfDELETE FROM … WHERE
ctea common table expression
bta transaction that rolls back (safe to try), with COMMIT commented out
tcBEGIN TRY … END TRY BEGIN CATCH THROW; END CATCH around the selection
ifexIF EXISTS (…) BEGIN … END
ctCREATE TABLE with an identity primary key
spCREATE OR ALTER PROCEDURE with SET NOCOUNT ON
fnCREATE OR ALTER FUNCTION (inline table-valued)
exEXEC
w, ob, gbWHERE, ORDER BY, GROUP BY
lj, ijLEFT JOIN, INNER JOIN

Tab then jumps between the snippet's placeholders. Edit these or add your own in Settings ▸ Snippets; a snippet can use $CURSOR$, $SELECTEDTEXT$, $DATE$, $USER$ and numbered placeholders such as ${1:name}.

Settings ▸ Snippets, listing the built-in snippets
Settings ▸ Snippets.

#Editing commands

Besides the usual text editing, the editor has the commands developers expect from their IDE (shortcuts in the Lukla keymap; see Keyboard shortcuts for the others):

CommandShortcut
Comment/uncomment lines⌘/
Block comment⌥⌘/
Duplicate line or selection⌘D
Delete line⇧⌘K
Move line up / down⌥⇧↑ / ⌥⇧↓
Join lines⌃⇧J
Expand / shrink selection⌃⇧↑ / ⌃⇧↓
Upper / lower case⇧⌘U / ⇧⌘L
Rename an alias or variable everywhere⇧F6
Go to definitionF12
Quick documentationF1
Find usages⌥F7
Go to line⌘L
  • Go to definition (F12) on a table, view, procedure or function opens its definition.
  • Quick documentation (F1) shows a table's columns and keys, or a procedure's parameters, in a popover.
  • Drag a table or column from Object Explorer into the editor to insert its bracketed name.

Other apps and scripts can open a query tab:

Terminal
open "lukla://editor"
open "lukla://query?sql=SELECT%201&connection=Local&database=Shop"