读取SqlServer表名及结构
读取表名:
方法1:
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'
方法2:
SELECT [name]as TableName FROM SYSOBJECTS WHERE xtype = 'U'
读取表结构:
select [name]as ColumnName,[xtype] as ColumnType from syscolumns
where id in(SELECT id FROM sysobjects where [name]='TABLENAME')
where id in(SELECT id FROM sysobjects where [name]='TABLENAME')
其中 xtype 为列的类型
56 是 int 类型,167 是 varchar 类型,231 是 nvarchar 类型,61 是 datetime 类型