SQL脚本如何在脚本中添加选项卡或新行
我有一个 SQL 脚本,它获取表名并为这些表创建触发器。当我创建触发器后打开触发器时,所有代码都在一行上。我将如何在脚本中添加制表符和换行符以使触发器更具可读性。
示例代码:
SET @SQL = 'ALTER TRIGGER [dbo].[TRG_' + SUBSTRING(@TABLE_NAME,5, LEN(@TABLE_NAME)) + '_$AUD] '
SET @SQL = @SQL + 'ON [dbo].[' + @TABLE_NAME + '] '
SET @SQL = @SQL + 'FOR UPDATE, DELETE '
SET @SQL = @SQL + 'AS '
SET @SQL = @SQL + 'DECLARE '
SET @SQL = @SQL + '@BIT INT, '
SET @SQL = @SQL + '@FIELD INT, '
SET @SQL = @SQL + '@CHAR INT '
I have a SQL script that acquires table names and creates trigger for those tables. When I open the trigger after creating it all of the code is on one line. How would I go about adding tab and new line characters within the script to make the trigger more readable.
Example code:
SET @SQL = 'ALTER TRIGGER [dbo].[TRG_' + SUBSTRING(@TABLE_NAME,5, LEN(@TABLE_NAME)) + '_$AUD] '
SET @SQL = @SQL + 'ON [dbo].[' + @TABLE_NAME + '] '
SET @SQL = @SQL + 'FOR UPDATE, DELETE '
SET @SQL = @SQL + 'AS '
SET @SQL = @SQL + 'DECLARE '
SET @SQL = @SQL + '@BIT INT, '
SET @SQL = @SQL + '@FIELD INT, '
SET @SQL = @SQL + '@CHAR INT '
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
至少对于 MS SQL,您可以使用 CHAR() 和正确的 ASCII 值并在字符串中的正确位置连接,或者您可以在 SQL 字符串本身中包含换行符、制表符等。该字符串可以跨越多行。例如,这应该有效:
For MS SQL at least, you can either use CHAR() with the correct ASCII values and concatenate at the correct places in your strings, or you can just include the newlines, tabs, etc. within your SQL strings themselves. The string can span multiple lines. For example, this should work:
这不会更改实际的触发器定义,但您可以使用 Instant SQL Formatter,当你需要处理它时。
This won't change the actual trigger definition, but you could use a tool like Instant SQL Formatter, when you need to work on it.
用这个
use this