Share via

How to extraxt views from SQL Server 2008R2

Sarvesh Pandey 146 Reputation points
2021-05-07T09:17:20.357+00:00

We have a SQL server 2008R2, we need to extract view create command but we couldn't find it and Generate scripts throws error message.
Any workaround or alternate way to extract create view command.

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


Answer accepted by question author

AmeliaGu-MSFT 14,016 Reputation points Microsoft External Staff
2021-05-10T06:30:12.67+00:00

Hi @Sarvesh Pandey ,
How are things going on?
Could you please share us the detailed error message?

Any workaround or alternate way to extract create view command.

You can script the view by right-click the view-> Script View as->CREATE To.
You also can get all views in the database using the following query:

USE <Databasename>  
Go  
SELECT S.definition  
FROM sys.sql_modules S  
INNER JOIN sys.Objects O  
ON S.Object_id = O.Object_id  
WHERE O.type = 'v'  

Please refer to this article which might help.

Best Regards,
Amelia


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Vaibhav Chaudhari 39,011 Reputation points Volunteer Moderator
    2021-05-07T09:40:21.807+00:00

    Try running - sp_helptext <view name> and also see suggestions given here -

    https://stackoverflow.com/questions/20189134/how-to-get-a-view-table-query-code-in-sql-server-2008-management-studio/46329520


    Please don't forget to Accept Answer and Up-vote if the response helped -- Vaibhav

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.