經常有朋友問怎麼得到access的表結構。
public
sub gettables()
dim rs as
new adodb.recordset
dim conn as adodb.connection
dim ssql as
string
set conn = currentproject.connection
ssql = "select id,name from msysobjects where type=1 and flags=0"
rs.open ssql, conn
dowhile
not rs.eof
debug.print "****"; rs.fields("name").value; "****************"
gettablecolumns rs.fields("name").value
rs.movenext
loop
rs.close
set rs = nothing
set conn = nothing
endsub
public
sub gettablecolumns(stablename as
string)
dim rs as
new adodb.recordset
dim conn as adodb.connection
dim fld as adodb.field
set conn = currentproject.connection
rs.open stablename, conn, , , adcmdtable
foreach fld in rs.fields
debug.print fld.name, sfldtype(fld.type), fld.numericscale, fld.precision
next
rs.close
set rs = nothing
set conn = nothing
endsub
public
function sfldtype(itype as
integer)
select
case itype
case 20
sfldtype = "bigint"
case 128
sfldtype = "binary"
case 11
sfldtype = "boolean"
case 8
sfldtype = "bstr"
case 136
sfldtype = "chapter"
case 129
sfldtype = "char"
case 6
sfldtype = "currency"
case 7
sfldtype = "date"
case 133
sfldtype = "dbdate"
case 134
sfldtype = "dbtime"
case 135
sfldtype = "dbtimestamp"
case 14
sfldtype = "decimal"
case 5
sfldtype = "double"
case 0
sfldtype = "empty"
case 10
sfldtype = "error"
case 64
sfldtype = "filetime"
case 72
sfldtype = "guid"
case 9
sfldtype = "idispatch"
case 3
sfldtype = "integer"
case 13
sfldtype = "iunknown"
case 205
sfldtype = "longvarbinary"
case 201
sfldtype = "longvarchar"
case 203
sfldtype = "longvarwchar"
case 131
sfldtype = "numeric"
case 138
sfldtype = "propvariant"
case 4
sfldtype = "single"
case 2
sfldtype = "smallint"
case 16
sfldtype = "tinyint"
case 21
sfldtype = "unsignedbigint"
case 19
sfldtype = "unsignedint"
case 18
sfldtype = "unsignedsmallint"
case 17
sfldtype = "unsignedtinyint"
case 132
sfldtype = "userdefined"
case 204
sfldtype = "varbinary"
case 200
sfldtype = "varchar"
case 12
sfldtype = "variant"
case 139
sfldtype = "varnumeric"
case 202
sfldtype = "varwchar"
case 130
sfldtype = "wchar"
case
else
sfldtype = "unknown"
endselect
endfunction
獲取Access系統表
access 系統表 msysobjects 包含了資料庫物件列表,儘管未在文件中記載,你仍可通過查詢它來獲取你想要的.注 請不要有意或無意地修改任何access系統表,否則會出現不可意料的情況.使用下列 sql 語句來獲取你想要的 查詢 select msysobjects.name from m...
獲取表結構
sql server 2000 feixian sql server 2000 select 表名 case when a.colorder 1 then d.name else end 表說明 case when a.colorder 1 then isnull f.value,else end ...
SqlServer 獲取表結構
1.獲取表的基本字段屬性 獲取sqlserver中表結構 select syscolumns.name,systypes.name,syscolumns.isnullable,syscolumns.length from syscolumns,systypes where syscolumns.xu...