sql.md

 1---
 2title: SQL
 3description: "Configure SQL language support in Zed, including language servers, formatting, and debugging."
 4---
 5
 6# SQL
 7
 8SQL files are handled by the [SQL Extension](https://github.com/zed-extensions/sql).
 9
10- Tree-sitter: [nervenes/tree-sitter-sql](https://github.com/nervenes/tree-sitter-sql)
11
12### Formatting
13
14Zed supports auto-formatting SQL using external tools like [`sql-formatter`](https://github.com/sql-formatter-org/sql-formatter).
15
161. Install `sql-formatter`:
17
18```sh
19npm install -g sql-formatter
20```
21
222. Ensure `sql-formatter` is available in your path and check the version:
23
24```sh
25which sql-formatter
26sql-formatter --version
27```
28
293. Configure formatting in Settings ({#kb zed::OpenSettings}) under Languages > SQL, or add to your settings file:
30
31```json [settings]
32  "languages": {
33    "SQL": {
34      "formatter": {
35        "external": {
36          "command": "sql-formatter",
37          "arguments": ["--language", "mysql"]
38        }
39      }
40    }
41  },
42```
43
44Substitute your preferred [SQL Dialect] for `mysql` above (`duckdb`, `hive`, `mariadb`, `postgresql`, `redshift`, `snowflake`, `sqlite`, `spark`, etc).
45
46You can add this to Zed project settings (`.zed/settings.json`) or via your Zed user settings (`~/.config/zed/settings.json`).
47
48### Advanced Formatting
49
50Sql-formatter also allows more precise control by providing [sql-formatter configuration options](https://github.com/sql-formatter-org/sql-formatter#configuration-options). To provide these, create a `.sql-formatter.json` file in your project:
51
52```json
53{
54  "language": "postgresql",
55  "tabWidth": 2,
56  "keywordCase": "upper",
57  "linesBetweenQueries": 2
58}
59```
60
61When using a `.sql-formatter.json` file you can use a simplified Zed settings configuration:
62
63```json [settings]
64{
65  "languages": {
66    "SQL": {
67      "formatter": {
68        "external": {
69          "command": "sql-formatter"
70        }
71      }
72    }
73  }
74}
75```