查询表中所有字段的最大长度
Posted 木龙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查询表中所有字段的最大长度相关的知识,希望对你有一定的参考价值。
DECLARE @tableName NVARCHAR(50)= ‘home‘; DECLARE @tmpTable TABLE ( ColumnName NVARCHAR(50) NOT NULL , ColumnMaxLen INT NOT NULL ); DECLARE @columnName NVARCHAR(50); DECLARE @columnMaxLen INT; DECLARE @sql NVARCHAR(MAX); DECLARE tmpCursor CURSOR FOR SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @tableName ORDER BY ORDINAL_POSITION FOR READ ONLY; OPEN tmpCursor; FETCH NEXT FROM tmpCursor INTO @columnName; WHILE @@FETCH_STATUS = 0 BEGIN SET @sql = ‘SELECT @columnMaxLen=ISNULL(MAX(LEN([‘ + @columnName + ‘])), 0) FROM ‘ + @tableName; -- PRINT @sql; EXEC sp_executesql @sql, N‘@columnMaxLen int out‘, @columnMaxLen OUT; INSERT @tmpTable ( ColumnName, ColumnMaxLen ) VALUES ( @columnName, @columnMaxLen ); FETCH NEXT FROM tmpCursor INTO @columnName; END; CLOSE tmpCursor; DEALLOCATE tmpCursor; SELECT * FROM @tmpTable;
以上是关于查询表中所有字段的最大长度的主要内容,如果未能解决你的问题,请参考以下文章
Solr Highlighting:如何为同一字段请求多个片段长度?