Views and their formatted text being lost

  • Issue: When editing a view (right click view, click 'Script view as', click 'alter to', 'click 'New query window'), all the formatting I spent hours and hours perfecting is lost!!

    When editing a stored procedure, all the formatting is how I last left it.

    Is there a way to keep the formatting in a view. It seems a waste of time to re-align column etc. each time.

    Thanks.

  • Sorry to be captain obvious, but you could always save your nicely formatted view definition as a file, and open it when you need it as opposed to doing a "script as". With the added bonus that you could then implement versioning or source control on the definition as well ...

  • Thanks for the suggestion, but we already use Redgate for source control. Keeping a copy of the view in a file is an option, but does add redundancy to the picture.

    I'll investigate if redgate source control tool can help and update. That was something I didn't think about.

  • One thing you can do is to use Red Gate SQL Prompt to format the query, whether it gets saved correctly or not.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Views maintain their formatting when created/altered like any other object. Is this a problem with how they're being applied in your deployment process/stored in Source Control?

  • May not be the issue here, but in SSMS, if someone opens the view using <Right-Click> Design, opening the view in the Query Designer, and then saves it, the formating and comments will be lost.

  • The nice features in the Query Designer that allow you to drag and drop tables into the query, drag columns around to complete joins, etc. means the UI takes control of the query text so it can present what was designed in the visual areas of the designer in the query text pane. Not much you can do about that. And unfortunately redgate SQL Prompt doesn't work its magic in the Query Designer.

    If you want ultimate control over your query formatting use the Query Window by right-clicking on the View, selecting Script View As, then Alter, then New Query window. From there you will be working with the actual view-definition, but of course only in its textual form. Altering the view in a Query Window will maintain its formatting whereas working with it in the Query Designer will not.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply