script out views in a database

  • Hi,

    I want to script out the views in a database using t-sql script. Can someone help me on this?

    Also, what permissions are required in order to view the views definition in a database?

    Thanks in advance,

    Manu

  • Right-click on the View and select Script VIEW as > and make the appropriate selections in the next menu.

    I'm not positive but I assume at least DBO rights are necessary. If you have sysadmin rights, you already have what you need.

  • Thanks Jim. But I need to generate script using query analyzer.

    Manu

  • It is really the same in Query Analyzer. Right-click on the view and make the appropriate scripting selection and destination.

  • You can select data from INFORMATION_SCHEMA.VIEWS to use in your script.

    Greg

  • You can also use sp_helptext and store the results in a variable for output. And, depending if you're using SQL 2000 or 2005, you can use the following:

    -- SQL 2005

    select definition from sys.sql_modules

    where object_name( object_id ) = 'vw1'

    -- SQL 2000

    select text from sys.syscomments

    where id = object_id ( 'vw1' )

    DAB

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

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