摘自:http://blog.163.com/tianshenglongchang@126/blog/static/164628503201231925214824/
查询除指定字段外的所有字段
declare @name varchar(100) declare @sql varchar(1000) SET @sql='select ' DECLARE C11 CURSOR FOR select name from syscolumns where id= (select max(id) from sysobjects where xtype='u' and name='表名') and name <> '除外的字段' OPEN C11 FETCH NEXT FROM C11 INTO @name IF @@FETCH_STATUS <> 0 BEGIN DEALLOCATE C11 RETURN END WHILE(@@FETCH_STATUS = 0) BEGIN SET @sql=@sql+@name+',' FETCH NEXT FROM C11 INTO @name END DEALLOCATE C11 set @sql=substring(@sql,1,len(@sql)-1)+' from 表名' exec (@sql)
--查询某表中所有字段
select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='表名')