您的位置:首页 > 其它

遍历每个表进行指定操作

2007-05-31 10:36 218 查看

use websitedb




declare @tablename varchar(50)


declare @sqlstr varchar(300)


declare table_cursor cursor for


select o.name


from syscolumns c inner join sysobjects o on o.id=c.id


where o.xtype='u' and c.name='userid'


order by o.name


open table_cursor


fetch next from table_cursor into @tablename


while(@@fetch_status=0)


begin


set @sqlstr = 'select '''+@tablename+''' as tablename,* from '+@tablename+' where userid=''qifei'''


exec(@sqlstr)


fetch next from table_cursor into @tablename


end


close table_cursor


deallocate table_cursor
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐