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;
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'
RequestTxtOverflow
will indicate this and then the full code can be found in DBC.TableTextV