项目中发现一批语言表的某个字段设的值太小了需要增大,因为涉及到很多张表,所以采用游标一张张的处理。
代码很简单
DECLARE @tableName NVARCHAR(50)
DECLARE @sql NVARCHAR(200) DECLARE LangTable CURSOR FOR
SELECT name FROM sys.tables WHERE name LIKE '%Language' OPEN LangTable
FETCH NEXT FROM LangTable INTO @tableName WHILE @@FETCH_STATUS = 0
BEGIN SET @sql = 'ALTER TABLE '+@tableName+' ALTER COLUMN LanguageDesc NVARCHAR(MAX)'
EXEC @sql FETCH NEXT FROM LangTable INTO @tableName END CLOSE LangTable
DEALLOCATE LangTable