Declare @ delStr nvarchar (500)
-Set @ delStr = '< script src = http://www.bkjia.com/cn. js>'
Set @ delStr = '<script src = http://www.bkjia.com/cn. js> </script>'
/*************************************** */
************/
Set nocount on
Declare @ tableName nvarchar (100), @ columnName nvarchar (100), @ tbID int, @ iRow int, @ iResult int
Declare @ SQL nvarchar (500)
Set @ iResult = 0
Declare cur cursor
Select name, id from sysobjects where xtype = 'U'
Open cur
Fetch next from cur into @ tableName, @ tbID
While @ fetch_status = 0
Begin
Declare cur1 cursor
-Xtype in (231,167,239,175) is of the char, varchar, nchar, and nvarchar types.
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 (convert (varchar (1000 ), ['+ @ columnName +']), "'+ @ delStr + "',"") where ['+ @ columnName +'] like "% '+ @ delStr +' % "'
Exec sp_executesql @ SQL
Set @ iRow = @ rowcount
Set @ iResult = @ iResult + @ iRow
If @ iRow> 0
Begin
Print 'table: '+ @ tableName +', column: '+ @ columnName +' updated '+ convert (varchar (10), @ iRow) + 'records ;'
End
Fetch next from cur1 into @ columnName
End
Close cur1
Deallocate cur1
Declare cur2 cursor
-Xtype in () is ntext or text
Select name from syscolumns where xtype in (99,35) and id = @ tbID
Open cur2
Fetch next from cur2 into @ columnName
While @ fetch_status = 0
Begin
Set @ SQL = 'Update ['+ @ tableName +'] set ['+ @ columnName +'] = replace (convert (nvarchar (1000 ), ['+ @ columnName +']), "'+ @ delStr + "',"") where ['+ @ columnName +'] like "% '+ @ delStr +' % "'
Exec sp_executesql @ SQL
Set @ iRow = @ rowcount
Set @ iResult = @ iResult + @ iRow
If @ iRow> 0
Begin
Print 'table: '+ @ tableName +', column: '+ @ columnName +' updated '+ convert (varchar (10), @ iRow) + 'records ;'
End
Fetch next from cur2 into @ columnName
End
Close cur2
Deallocate cur2
Fetch next from cur into @ tableName, @ tbID
End
Print 'database total '+ convert (varchar (10), @ iResult) +' records updated !!! '
Close cur
Deallocate cur
Set nocount off
From: webshell. cc