SQL Server Update 所有表的某一列(列名相同,类型相同)数值

DECLARE @sql VARCHAR(5000);
WITH T
AS (SELECT SchemaName = c.TABLE_SCHEMA,
           TableName = c.TABLE_NAME,
           ColumnName = c.COLUMN_NAME,
           DataType = DATA_TYPE,
           sql = 'update ' + c.TABLE_NAME + ' set ' + c.COLUMN_NAME + ' = ''2017-11-20''' -----------执行语句
    FROM INFORMATION_SCHEMA.COLUMNS c
        INNER JOIN INFORMATION_SCHEMA.TABLES t
            ON c.TABLE_NAME = t.TABLE_NAME
               AND c.TABLE_SCHEMA = t.TABLE_SCHEMA
               AND t.TABLE_TYPE = 'BASE TABLE'
               AND c.COLUMN_NAME LIKE '%CreateTime%' ---列名
               AND c.DATA_TYPE = 'datetime'),
     T2
AS (SELECT STUFF(
           (
               SELECT '; ' + A.sql FROM T A FOR XML PATH('')
           ),
           1,
           1,
           ''
                ) AS sqls)
SELECT @sql = sqls
FROM T2;
PRINT @sql;
EXEC (@sql);

 

上一篇:白帽黑客发现上帝模式共享服务器数据库漏洞


下一篇:matlab体验svm算法【非实现】