当前位置: 代码迷 >> 综合 >> SqlServer2008实例36视图之查询视图定义
  详细解决方案

SqlServer2008实例36视图之查询视图定义

热度:8   发布时间:2024-02-02 13:53:58.0

  可以通过查询sys.sql_modules系统目录视图来查看视图的T-SQL定义。
查询某个视图的SQL定义:

USE AdventureWorks
GOSELECT 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'  

  相关解决方案