Lukla Data Studio Docs

Docs Editor

Formatting

Format T-SQL with a built-in style or your own profile, with a live preview, and share profiles with your team.

On this page
  1. Built-in styles
  2. Standard
  3. Compact
  4. Leading commas
  5. River
  6. Indented
  7. Make your own profile
  8. Share profiles

⇧⌘F formats the selection, or the statement under the cursor. The menu next to the Format button picks the style. The formatter refuses rather than change what your SQL does: if a result wouldn't parse the same way, nothing changes.

Settings ▸ Formatting: the built-in styles and your profiles on the left, their settings, and a live preview
Settings ▸ Formatting, with the preview updating as you change a setting.

#Built-in styles

The same query in each style:

T-SQL
select c.City, count(*) as Orders, sum(o.Total) as Revenue from dbo.Orders o join dbo.Customers c on c.Id = o.CustomerId where o.Status = N'Shipped' and o.Total > 100 group by c.City order by Revenue desc;

#Standard

Keywords start their lines, one column per line, joins and extra conditions indented.

T-SQL
SELECT
    c.City,
    COUNT(*) AS Orders,
    SUM(o.Total) AS Revenue
FROM dbo.Orders o
    JOIN dbo.Customers c ON c.Id = o.CustomerId
WHERE o.Status = N'Shipped'
    AND o.Total > 100
GROUP BY c.City
ORDER BY Revenue DESC;

#Compact

Each clause on one line.

T-SQL
SELECT c.City, COUNT(*) AS Orders, SUM(o.Total) AS Revenue
FROM dbo.Orders o
JOIN dbo.Customers c ON c.Id = o.CustomerId
WHERE o.Status = N'Shipped' AND o.Total > 100
GROUP BY c.City
ORDER BY Revenue DESC;

#Leading commas

Commas start the line, so a column is easy to comment out.

T-SQL
SELECT
      c.City
    , COUNT(*) AS Orders
    , SUM(o.Total) AS Revenue
FROM dbo.Orders o
    JOIN dbo.Customers c ON c.Id = o.CustomerId
WHERE o.Status = N'Shipped'
    AND o.Total > 100
GROUP BY c.City
ORDER BY Revenue DESC;

#River

Clause keywords right-aligned on a "river", so the clauses line up.

T-SQL
SELECT c.City,
       COUNT(*) AS Orders,
       SUM(o.Total) AS Revenue
  FROM dbo.Orders o
  JOIN dbo.Customers c
    ON c.Id = o.CustomerId
 WHERE o.Status = N'Shipped'
   AND o.Total > 100
 GROUP BY c.City
 ORDER BY Revenue DESC;

#Indented

Every clause's body indented under its keyword.

T-SQL
SELECT
    c.City,
    COUNT(*) AS Orders,
    SUM(o.Total) AS Revenue
FROM
    dbo.Orders o
    JOIN dbo.Customers c
        ON c.Id = o.CustomerId
WHERE
    o.Status = N'Shipped'
    AND o.Total > 100
GROUP BY
    c.City
ORDER BY
    Revenue DESC;

#Make your own profile

Built-in styles don't change: changing any setting while one is selected saves your own copy under My profiles. Each profile sets:

  • Case and spacing: keyword case, tabs or spaces, indent width and line width.
  • Layout: right-aligned clause keywords (river), one list item per line or packed, commas at the start of lines, a single item kept on the keyword's line, where WHERE/HAVING conditions go, JOIN indented under FROM, ON on its own line, and the FROM/INTO/VALUES target on the next line.

The preview on the right shows a sample script in the profile as you change it.

#Share profiles

The export button under the list saves a profile as a .json file; import loads one, so a team can share one style. Imported values are checked and kept within sensible limits.