How to Retrieve the Original SELECT Statements

Glasier 440 Reputation points
2024-09-20T17:06:31.89+00:00

At present, the data warehouse contains numerous views, and I need to modify several of them. The challenge is that I’m not sure how these views were originally created. Is there a query in Synapse to check the view definitions, particularly the SELECT statements used to create them?

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,997 questions
0 comments No comments
{count} votes

Accepted answer
  1. Smaran Thoomu 16,890 Reputation points Microsoft Vendor
    2024-09-20T21:31:22.24+00:00

    Hi @Glasier

    Thanks for the question and using MS Q&A platform.

    Adding to the above answer, unfortunately, p_helptext is not supported in Synapse Analytics. However, you can use the view sys.sql_modules and its definition column to get the SQL text for a view. For example, you can use the following query to retrieve the SQL text for a view:

    SELECT
    

    Alternatively, you can use the OBJECT_DEFINITION function to retrieve the SQL text for a view. Here is an example query:

    SELECT
    

    Replace 'your_view_name' with the name of the view you want to retrieve the definition for. This query will return the original SELECT statement used to create the view.

    For more information, please refer: https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-sql-modules-transact-sql?view=sql-server-ver15

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Olaf Helper 45,106 Reputation points
    2024-09-20T17:17:25.39+00:00

    how these views were originally created.

    If you haven't any kind of source controll, then it's not possible to get older source code.

    0 comments No comments

Your answer

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