可以通过查询sys.sql_modules系统目录视图来查看视图的T-SQL定义。
查询某个视图的SQL定义:
USE AdventureWorks
GO
SELECT definition FROM sys.sql_modules
WHERE object_id=OBJECT_ID('dbo.v_Product_TransactionHistory')
查询返回
CREATE VIEW dbo.v_Product_TransactionHistory AS SELECT p.Name ProductName, p.ProductNumber, c.Name ProductCategory, s.Name ProductSubCategory, m.Name ProductModel, t.TransactionID, t.ReferenceOrderID, t.ReferenceOrderLineID, t.TransactionDate, t.TransactionType, t.Quantity, t.ActualCost FROM Production.TransactionHistory t INNER JOIN Production.Product p ON t.ProductID=p.ProductID INNER JOIN Production.ProductModel m ON m.ProductModelID=p.ProductModelID INNER JOIN Production.ProductSubcategory s ON s.ProductSubcategoryID=p.ProductSubcategoryID INNER JOIN Production.ProductCategory c ON c.ProductCategoryID=s.ProductCategoryID WHERE c.Name='Bikes'