选择一个服务器后,列出该服务器中所有数据库:
Select * from Master.dbo.sysdatabases;
选择一个库后读该库中表:
select * from dbo.sysobjects where OBJECTPROPERTY(id, N'IsUserTable') = 1;
列出表中的字段:
select c.name as ColumnName, c.colorder as ColumnOrder, c.xtype as DataType, typ.name as DataTypeName, c.Length, c.isnullable from dbo.syscolumns c inner join dbo.sysobjects t
on c.id = t.id
inner join dbo.systypes typ on typ.xtype = c.xtype
where OBJECTPROPERTY(t.id, N'IsUserTable') = 1
and t.name='" + tableName + "' order by c.colorder";