1

How to get all CREATE VIEW statements with a single query?

This Query is used to get the definition of a single view:

show view db.tablename;

1 Answer 1

0

You'll need to use the catalog views (h/t to Dieter for alerting me to truncation of RequestText in TablesV):

SELECT
  Tbl.DatabaseName
 ,Tbl.TableName
 ,COALESCE(TblText.LineNo,1) AS LineNo
 ,COALESCE(TblText.RequestText,Tbl.RequestText) AS RequestText
FROM
  DBC.TablesV Tbl
LEFT JOIN
  DBC.TableTextV TblText
    ON TblText.DatabaseName = Tbl.DatabaseName
            AND TblText.TableName = Tbl.TableName
        AND TblText.TableKind = Tbl.TableKind
WHERE
  DatabaseName = <Database name>
    AND TableKind = 'V'
1
  • 1
    Request Text will have the DDL truncated when it's too large. RequestTxtOverflow will indicate this and then the full code can be found in DBC.TableTextV
    – dnoeth
    Commented Jan 27, 2021 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.