DECLARE My_Cursor CURSOR --定义游标 declare@indexId int FOR (SELECT * FROM dbo.GalleryPhoto) --查出需要的集合放到游标中 OPEN My_Cursor; --打开游标 FETCH NEXT FROM My_Cursor ; --读取第一行数据 WHILE @@FETCH_STATUS = 0 BEGIN @indexId=@@FETCH_STATUS+1; UPDATE dbo.GalleryPhoto SET folder = replace(folder,'UserFilesGallery','') WHERE CURRENT OF My_Cursor; --更新 FETCH NEXT FROM My_Cursor; --读取下一行数据 END CLOSE My_Cursor; --关闭游标 DEALLOCATE My_Cursor; --释放游标