首页 > 解决方案 > 如何格式化 SQL 插入以对齐逗号分隔符?

问题描述

我有一个将初始数据插入/合并到表中的部署后脚本。我想格式化插入脚本,以便插入的每一行都具有相同的长度。我希望能够按住 alt 单击并为每条记录选择相同的列。

insert 语句中的值的格式为:

(123, 'File_X', 'ShortString'), 
(124, 'File_XYZ', 'LoooonnnngString'), 

我想要实现的是这种格式:

(123, 'File_X'  , 'ShortString'     ),
(124, 'File_XYZ', 'LoooonnnngString'), 

我找不到任何可以配置为实现此目的的格式化程序。

标签: sqlformatting

解决方案


I wrote it as a comment, but as suggested by @zimek-atomek I'll make it as an answer to be clearer.

To align all the columns in the file, you can use the plugin in for Visual Studio Code called Rainbow CSV (https://marketplace.visualstudio.com/items?itemName=mechatroner.rainbow-csv)

Since the file you are going to align contains commas (but it also support other delimiters), you can use the align columns feature mentioned in the list at the beginning of the page.


推荐阅读