我知道您可以在SQL视图中放置查询,但我正在尝试在SQL视图中获取表,因此我可以看到create table语句。
答案 0 :(得分:1)
据我所知,没有内置的方式在Access中显示create table
表达式。
但是,您可以创建自己的VBA函数,其功能恰好如下:
public function showCreateTable(tblName as String) as String
dim db as DAO.Database, tbl as DAO.TableDef, fld as DAO.field
dim field
dim strSQL as string
dim i as integer
set db = currentdb()
for each tbl in db.tableDefs
if tbl.Name = tblName then
strSQL = "create table " & tblName & "("
i = 1
for each fld in tbl.fields
if i > 1 then
strSQL = strSQL & ", " & vbCrLf
else
strSQL = strSQL & vbCrLf
end if
strSQL = strSQL & fld.Name & " "
select case fld.Type
case dbBigInt: strSQL & "bigint"
case dbBinary: strSQL = strSQL & "binary"
case dbBoolean: strSQL & "boolean"
case dbChar: strSQL = strSQL & "char("& fld.size & ")"
' You go on with every type listed in the Field.Type possible values
end select
i = i+1
next fld
strSQL = strSQL & vbCrLf & ")"
exit for
end if
next tbl
showCreateTable = strSQL
end function
列出了Field.Type
个可能的值here。