清理 CREATE TABLE 列布局
我有一系列如下所示的 sql 脚本:
CREATE TABLE table_one
(
column_one int not null,
column_two varchar(100) not null,
column_three_four_five int,
column_six decimal(16,4) null,
PRIMARY KEY ( column_one, column_three_four_five)
);
我想清理布局以使其更易于扫描,如下所示:
CREATE TABLE table_one
(
column_one int not null,
column_two varchar(100) not null,
column_three_four_five int,
column_six decimal(16,4) null,
PRIMARY KEY
(
column_one,
column_three_four_five
)
);
确切的布局不如能够创建干净的外观以提高可读性重要。 (请阅读:请不要对格式本身进行攻击)-grin-
编写此脚本的好方法是什么(我正在看着你,Perl 大神......)?
I've got a series of sql scripts that look like this:
CREATE TABLE table_one
(
column_one int not null,
column_two varchar(100) not null,
column_three_four_five int,
column_six decimal(16,4) null,
PRIMARY KEY ( column_one, column_three_four_five)
);
I'd like to clean up the layout to be easier to scan, something like this:
CREATE TABLE table_one
(
column_one int not null,
column_two varchar(100) not null,
column_three_four_five int,
column_six decimal(16,4) null,
PRIMARY KEY
(
column_one,
column_three_four_five
)
);
The exact layout is less important than being able to create a clean look to improve readability. (read: please don't flame the formatting itself) -grin-
What would be a good way to script this (I'm looking at you, Perl gods...)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,不能说它适用于所有文件,但类似这样的东西就可以完成这项工作...
示例文件 data.sql
输出:
Hmmmmm well can't say it will work for all your files but something like this would do the job ...
sample file data.sql
output:
我还没有尝试过其中任何一个,但 CPAN 有 SQL::Beautify 和 < a href="http://search.cpan.org/perldoc?SQL::QueryBuilder::Pretty" rel="nofollow noreferrer">SQL::QueryBuilder::Pretty。
I haven't tried either one, but CPAN has SQL::Beautify and SQL::QueryBuilder::Pretty.
http://www.dpriver.com/pp/sqlformat.htm
不是脚本。但我现在不想编写任何代码。
对于任何语言中的此类内容,请查找格式化程序或“漂亮”一词来表示预构建的垃圾。
http://www.dpriver.com/pp/sqlformat.htm
Not a script. But I don't want to code anything right now.
For stuff like this in any language look for formatters or the word 'pretty' for prebuilt junk.