gpt4 book ai didi

tsql - INFORMATION_SCHEMA.VIEWS 中的 View_Definition 限制为 4000 个字符

转载 作者:行者123 更新时间:2023-12-05 03:06:54 25 4
gpt4 key购买 nike

我通过运行这个查询来备份我的所有 View ,并将结果存储在一个表中:

select 
TABLE_CATALOG as DBName
, TABLE_NAME as ViewName
, VIEW_DEFINITION as ViewDef
, datalength(VIEW_DEFINITION) as [Length]
, GETDATE() as ImportDate
from INFORMATION_SCHEMA.VIEWS
order by DBName, ViewName

但是 VIEW_DEFINITION 列的数据类型设置为 nvarchar(4000),我的一些 View 比这长得多 - 所以它们被截断了。

Columns in INFORMATION_SCHEMA.VIEWS

我能否以某种方式将 VIEW_DEFINITION 列的数据类型更改为 varchar(max)?

最佳答案

因为 INFORMATION_SCHEMA.VIEWS 是一个 View ,您可以运行 EXEC sp_helptext 'information_schema.views' 来找出定义。这返回

CREATE VIEW INFORMATION_SCHEMA.VIEWS
AS
SELECT DB_NAME() AS TABLE_CATALOG ,
SCHEMA_NAME(schema_id) AS TABLE_SCHEMA ,
name AS TABLE_NAME ,
CONVERT(NVARCHAR(4000), OBJECT_DEFINITION(object_id)) AS VIEW_DEFINITION ,
CONVERT(VARCHAR(7) ,
CASE with_check_option
WHEN 1 THEN 'CASCADE'
ELSE 'NONE'
END) AS CHECK_OPTION ,
'NO' AS IS_UPDATABLE
FROM sys.views;

从那里只需编辑即可获得您需要的内容

SELECT  
DB_NAME() AS DBName,
name AS ViewName,
OBJECT_DEFINITION(object_id) AS ViewDef,
LEN(OBJECT_DEFINITION(object_id)) AS [Length],
GETDATE() AS ImportDate
FROM
sys.views

关于tsql - INFORMATION_SCHEMA.VIEWS 中的 View_Definition 限制为 4000 个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48791194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com