我们知道(select * from 表名 )可以查询出数据库中所有字段的内容,
那么select * 查出来的字段的顺序是怎么回事呢?其实我们同样可以通过下面的方式查询出来。
查询出来的字段和select * 查出来的字段顺序是一一对应的。
--表的字段名称
select name from syscolumns where id=object_id( '表名 ')--表的字段数
select count(name) from syscolumns where id=object_id( '表名 ')
最好改成:object_id(N '表名 ')
这样只是规范一些,一般不会出错
扩展知识:
select name from syscolumns where id=object_id(N '表名 ') --查询列名select name from sysobjects where xtype= 'U ' --查询数据库中表名
select name from sysobjects where xtype= 'P ' --查询数据库中存储过程