简体   繁体   English

SQL Server 2008/2012-视图和SQL格式

[英]SQL Server 2008 / 2012 - views & sql formatting

Hopefully this is a newbie question. 希望这是一个新手问题。

So if I have kind of a long set of selects in my SQL and a couple of sub-selects within my where clause, I'm less than satisfied with the formatting in the view designer, which appears to be the only way to display/show my views after they are saved. 因此,如果我在SQL中有很长的选择集,而在where子句中有几个子选择,那么我对视图设计器中的格式就不太满意,这似乎是显示/保存后显示我的视图。

So, in short, is there any way to directly edit my views within SSMS, and have the views retain the formatting in my code? 简而言之,有什么方法可以直接在SSMS中编辑我的视图,并使视图保留代码中的格式吗?

ie;

select case /*comment */
  when a = 5  
   then b = 2 
   else b = 4  /* why b 4 */
  end as field_1,
  dt as field_2,...

get's all mashed up 都捣碎了

select case /*comment */     when a = 5                  
then b = 2                 else b = 4  /* why b 4 */              
end as field_1,             
dt as field_2,...

Or something along those lines. 或类似的规定。

Are you using the query designer? 您正在使用查询设计器吗? Instead, use an SSMS query window. 而是使用SSMS查询窗口。 From the SSMS Object Explorer, right-click on the view and select Script View as-->Alter To-->New Query Editor window. 在SSMS Object Explorer中,右键单击视图,然后选择Script View as-> Alter To-> New Query Editor窗口。 Format the view source in the query window and run the script to change the view. 在查询窗口中设置视图源的格式,然后运行脚本以更改视图。 Your formatting will be preserved. 您的格式将被保留。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM