日期:2014-05-18  浏览次数:20475 次

请问怎么根据数据库的用户表和列生成一条sql语句?
用户表   table1   有两个列col1,col2
我想生成这样一条语句
select   col1,col2   from   table1

数据库的每个用户表都生成这样一条sql   语句。
请给出sql   语句,以前见过,没找到,自己不想写了。

谢谢。

------解决方案--------------------
sp_msforeachtable @command1= "declare @a varchar(100);select @a=isnull(@a+ ', ', ' ')+name from syscolumns where id=object_id( '? ');select 'select '+@a+ ' from ? '
"