本文主要是介绍sql server 把表的所有的null改为0,不要限制某列,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
DECLARE @tableName NVARCHAR(256) = 'Linear' -- 替换为你的表名
DECLARE @sql NVARCHAR(MAX) = '' SELECT @sql += 'UPDATE ' + @tableName + ' SET ' + COLUMN_NAME + ' = 0 WHERE ' + COLUMN_NAME + ' IS NULL;'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @tableName AND TABLE_SCHEMA='dbo' AND DATA_TYPE IN ('int','nchar', 'float', 'decimal', 'money', 'smallmoney') AND IS_NULLABLE='YES' EXEC sp_executesql @sql
DECLARE @tableName NVARCHAR(256) = ‘Linear’ – 替换为你的表名
DECLARE @sql NVARCHAR(MAX) = ‘’
SELECT @sql += ‘UPDATE ’ + @tableName + ’ SET ’ + COLUMN_NAME + ’ = 0 WHERE ’ + COLUMN_NAME + ’ IS NULL;’
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @tableName AND TABLE_SCHEMA=‘dbo’ AND DATA_TYPE IN (‘int’,‘nchar’, ‘float’, ‘decimal’, ‘money’, ‘smallmoney’) AND IS_NULLABLE=‘YES’
EXEC sp_executesql @sql
这篇关于sql server 把表的所有的null改为0,不要限制某列的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!