6
4

3 回答 3

20

Stop using the clunky and buggy view designer.

For a new view, just open a new query window and start typing. This will work fine:

USE MyDatabase;
GO

CREATE VIEW dbo.MyView
AS
  -- this view is cool
  SELECT whatever FROM dbo.wherever;

For an existing view, right-click the view and choose Script As > Alter instead. This will give you a much better experience (minus the ability to check and uncheck columns etc).

enter image description here

The various visual designers may look like they'll save you time (and the intentions were certainly good), but the implementation is terrible, there are all kinds of bugs and limitations, and they really haven't been improved or even touched in years.

于 2013-10-15T12:53:35.983 回答
11

When you're creating database objects there are two places you can store comments. Before the object definition (and after any GO statements) and inside the object itself.

USE GODUCKS;
-- This comment will not be preserved
GO
-- This comment precedes the view definition
-- This too 
CREATE VIEW dbo.CommentedView
AS
    -- This comment lives inside the view
    SELECT 1 AS MyColumn;

Hit F5 and then script the view back out. You can see where the comments have/have not been preserved.

USE [GODUCKS]
GO

/****** Object:  View [dbo].[CommentedView]    Script Date: 10/15/2013 8:12:49 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- This comment precedes the view definition
-- This too 
CREATE VIEW [dbo].[CommentedView]
AS
    -- This comment lives inside the view
    SELECT 1 AS MyColumn;

GO
于 2013-10-15T13:14:09.107 回答
0

You can add comments in the Design View if you show the property editor. You want to add comments in the "SQL Comment" field in the "View Designer" group. This comment will display even if the view is opened as Script as well.

于 2022-02-23T15:12:00.047 回答