Monday, March 12, 2012

Placing Comments In Views

Is it possible to add comment lines to views? I tried using -- and /* . . .
but these lines were removed upon save. I tried using the property window,
but that cleared out my query.Yes, make sure you have the comment inside the CREATE VIEW, such as
CREATE VIEW v
AS
--MyComment
SELECT 1 AS a
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jim" <Jim@.discussions.microsoft.com> wrote in message
news:53FCF340-8E7A-495C-BD84-0C8A7882B001@.microsoft.com...
> Is it possible to add comment lines to views? I tried using -- and /* . . .
> but these lines were removed upon save. I tried using the property window,
> but that cleared out my query.|||I did what you suggested, but it still didn't do what I expected. So, I used
a query as simple as yours . . . and it did do what I expected. Could it be
that the comments in the property window don't work on views with UNION
queries?
Just to be clear: If I access the property window within DESIGN mode, the
comments do not appear. But if I access the property box from the list of
all views window, I do see my comment after the CREATE VIEW statement.
"Tibor Karaszi" wrote:
> Yes, make sure you have the comment inside the CREATE VIEW, such as
> CREATE VIEW v
> AS
> --MyComment
> SELECT 1 AS a
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Jim" <Jim@.discussions.microsoft.com> wrote in message
> news:53FCF340-8E7A-495C-BD84-0C8A7882B001@.microsoft.com...
> > Is it possible to add comment lines to views? I tried using -- and /* . . .
> > but these lines were removed upon save. I tried using the property window,
> > but that cleared out my query.
>|||Probably some GUI problem with Enterprise Manager. I did a simple test with below view:
CREATE VIEW v2
AS
--MyComment
SELECT 1 AS a
UNION ALL
SELECT 1 AS a
And the comment does not show, as you say. I don't use EM for view design myself. My guess is that
with a more complex query, the parsing that EM does of the view isn't smart enough to extract the
comment. I guess you could call it a bug and open a case with MS for it. I prefer writing the views
from Query analyzer...
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jim" <Jim@.discussions.microsoft.com> wrote in message
news:04C89683-D9BF-482A-AFBF-7915F0621F85@.microsoft.com...
>I did what you suggested, but it still didn't do what I expected. So, I used
> a query as simple as yours . . . and it did do what I expected. Could it be
> that the comments in the property window don't work on views with UNION
> queries?
> Just to be clear: If I access the property window within DESIGN mode, the
> comments do not appear. But if I access the property box from the list of
> all views window, I do see my comment after the CREATE VIEW statement.
> "Tibor Karaszi" wrote:
>> Yes, make sure you have the comment inside the CREATE VIEW, such as
>> CREATE VIEW v
>> AS
>> --MyComment
>> SELECT 1 AS a
>>
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://www.solidqualitylearning.com/
>> Blog: http://solidqualitylearning.com/blogs/tibor/
>>
>> "Jim" <Jim@.discussions.microsoft.com> wrote in message
>> news:53FCF340-8E7A-495C-BD84-0C8A7882B001@.microsoft.com...
>> > Is it possible to add comment lines to views? I tried using -- and /* . . .
>> > but these lines were removed upon save. I tried using the property window,
>> > but that cleared out my query.
>>|||Just one more note: if I add the comments via script, but then make a change
via EM and/or Visual Studio - saving the changes loses the comment lines.
But thanks, I got what I need . . . I'll just make sure the comments are in
the scripts we deliver to our customers.
"Tibor Karaszi" wrote:
> Probably some GUI problem with Enterprise Manager. I did a simple test with below view:
> CREATE VIEW v2
> AS
> --MyComment
> SELECT 1 AS a
> UNION ALL
> SELECT 1 AS a
> And the comment does not show, as you say. I don't use EM for view design myself. My guess is that
> with a more complex query, the parsing that EM does of the view isn't smart enough to extract the
> comment. I guess you could call it a bug and open a case with MS for it. I prefer writing the views
> from Query analyzer...
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Jim" <Jim@.discussions.microsoft.com> wrote in message
> news:04C89683-D9BF-482A-AFBF-7915F0621F85@.microsoft.com...
> >I did what you suggested, but it still didn't do what I expected. So, I used
> > a query as simple as yours . . . and it did do what I expected. Could it be
> > that the comments in the property window don't work on views with UNION
> > queries?
> >
> > Just to be clear: If I access the property window within DESIGN mode, the
> > comments do not appear. But if I access the property box from the list of
> > all views window, I do see my comment after the CREATE VIEW statement.
> >
> > "Tibor Karaszi" wrote:
> >
> >> Yes, make sure you have the comment inside the CREATE VIEW, such as
> >>
> >> CREATE VIEW v
> >> AS
> >> --MyComment
> >> SELECT 1 AS a
> >>
> >>
> >>
> >> --
> >> Tibor Karaszi, SQL Server MVP
> >> http://www.karaszi.com/sqlserver/default.asp
> >> http://www.solidqualitylearning.com/
> >> Blog: http://solidqualitylearning.com/blogs/tibor/
> >>
> >>
> >> "Jim" <Jim@.discussions.microsoft.com> wrote in message
> >> news:53FCF340-8E7A-495C-BD84-0C8A7882B001@.microsoft.com...
> >> > Is it possible to add comment lines to views? I tried using -- and /* . . .
> >> > but these lines were removed upon save. I tried using the property window,
> >> > but that cleared out my query.
> >>
> >>
>

No comments:

Post a Comment