sql语句_实现查询库中所有表的所有字段中包含XX的删除
时间:2011-01-18 来源:yond
DECLARE @tabName VARCHAR(40),@colName VARCHAR(40)
DECLARE @sql VARCHAR(200)
DECLARE tabCursor CURSOR FOR
SELECT name From sysobjects WHERE xtype = 'u' AND name <> 'dtproperties'
OPEN tabCursor
FETCH NEXT FROM tabCursor INTO @tabName
WHILE @@fetch_status = 0
BEGIN
SET @sql = 'UPDATE ' + @tabName + ' SET '
DECLARE colCursor CURSOR FOR Select Name FROM SysColumns Where id=Object_Id(@tabName)
OPEN colCursor
FETCH NEXT FROM colCursor INTO @colName
WHILE @@fetch_status = 0
BEGIN
SET @sql = @sql + @colName + '=REPLACE(' +@colName+ ',''XX'',''''),'
FETCH NEXT FROM colCursor INTO @colName
END
SET @sql = LEFT(@sql,LEN(@sql)-1)
EXEC(@sql)
CLOSE colCursor
DEALLOCATE colCursor
FETCH NEXT FROM tabCursor INTO @tabName
END
CLOSE tabCursor
DEALLOCATE tabCursor