Monu Tools

Định dạng SQL

Định dạng và làm đẹp truy vấn SQL với ngắt dòng theo mệnh đề và viết hoa từ khóa nhất quán, hoặc thu gọn chúng về một dòng.

Cách dùng Định dạng SQL

  1. 01

    Dán truy vấn SQL của bạn vào ô đầu vào.

  2. 02

    Chọn Định dạng để làm đẹp hoặc Thu gọn để nén về một dòng.

  3. 03

    Chọn cách viết hoa từ khóa, rồi sao chép kết quả.

What the SQL formatter does

This is a SQL formatter that takes a cramped, single-line or inconsistently styled query and beautifies it: each major clause on its own line, columns and conditions indented, and keyword casing made consistent. It can also do the reverse and minify a query to one line.

Why readable SQL helps

Readable SQL is easier to review, debug and maintain. When SELECT, FROM, WHERE, JOIN and GROUP BY each start a new line and the keywords share one casing, the shape of the query, what it returns and how it filters, becomes obvious at a glance.

Formatting is also useful right before committing a query so diffs stay small and reviewers see meaningful changes rather than reflowed whitespace.

Options and dialects

You choose the keyword casing (for example uppercase keywords, which is the common convention) and whether to format or minify. The formatter is dialect-agnostic and handles the common ANSI SQL used by PostgreSQL, MySQL, SQLite and SQL Server.

Minify mode is handy for the opposite need: collapsing a formatted query back to a single line to embed in code or a config value.

It formats, it does not validate

The tool formats for readability rather than checking that your query is valid, so it will happily lay out a query with a typo in it. Treat clean output as a readability win, not a correctness check.

Runs in your browser

Everything runs in your browser, which matters because real queries often contain table names, column names and sometimes literal values that hint at your schema or data. None of that is uploaded.

Câu hỏi thường gặp

Trình định dạng làm gì?

Nó đặt mỗi mệnh đề lớn như SELECT, FROM, WHERE và JOIN trên một dòng riêng, thụt lề các cột và điều kiện, và chuẩn hóa cách viết hoa từ khóa để dễ đọc.

SQL của tôi có được gửi đến máy chủ không?

Không. Việc định dạng chạy hoàn toàn trong trình duyệt của bạn, nên truy vấn của bạn không bao giờ rời khỏi thiết bị. Điều đó làm cho nó an toàn với các truy vấn đề cập đến tên bảng hoặc cột.

Những phương ngữ SQL nào được hỗ trợ?

Nó không phụ thuộc phương ngữ và xử lý ANSI SQL phổ biến được PostgreSQL, MySQL, SQLite và SQL Server dùng. Nó định dạng để dễ đọc chứ không kiểm tra cú pháp.

Nhúng công cụ này

Thêm công cụ này vào trang web của riêng bạn. Sao chép đoạn mã bên dưới; nó tự động cập nhật.

<iframe src="https://monu.tools/embed/vi/sql-formatter" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>

Công cụ liên quan