SQL INFORMATION_SCHEMA.VIEWS

SQL INFORMATION_SCHEMA.VIEWS

我想为所有视图内容创建包含 2019 年的 2020 年,但我对长 views.Is 视图定义列有字符限制有问题?因为据我所知,视图太长存在问题codes.Is有补救措施吗?

declare @Icerik varchar(max)
declare pcursor cursor
for
SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME like '%2019%'
open pcursor
fetch next from pcursor into @Icerik
    while @@FETCH_STATUS = 0
        begin
            set @Icerik = replace(@Icerik,'2019','2020')
            exec (@Icerik)
            fetch next from pcursor into @Icerik
        end
    close pcursor
    deallocate pcursor

Is View Definition column has a character limit?

来自INFORMATION_SCHEMA.VIEWS

VIEW_DEFINITION nvarchar(4000) If the length of definition is larger than nvarchar(4000), this column is NULL. Otherwise, this column is the view definition text.


我建议使用sys.sql_modules

definition nvarchar(max) SQL text that defines this module. This value can also be obtained using the OBJECT_DEFINITION built-in function.

db<>fiddle

或者SELECT OBJECT_DEFINITION(OBJECT_ID('schema.view_name'))