【发布时间】:2009-05-26 07:26:02
【问题描述】:
你能提供一个相当于 MySQL 'CREATE TABLE IF NOT EXISTS ...' 的 MS Access 吗?
更新
类似的东西
IF <no such table>
CREATE TABLE history(<fields>)
也适合
【问题讨论】:
-
如果重要的话,专门访问 2003
你能提供一个相当于 MySQL 'CREATE TABLE IF NOT EXISTS ...' 的 MS Access 吗?
更新
类似的东西
IF <no such table>
CREATE TABLE history(<fields>)
也适合
【问题讨论】:
对于 SQL DDL 代码,答案是否定的。 ACE/Jet SQL 没有任何流控制语法,ACE/Jet PROCEDURE 只能执行一条 SQL 语句。是的,没错:ACE/Jet PROCEDURE 不支持程序代码 :(
【讨论】:
这是通过 VBA 实现的方法:
Sub ViaVBA()
Const strSQLCreateFoo_c As String = _
"CREATE TABLE Foo" & _
"(" & _
"MyField1 INTEGER," & _
"MyField2 Text(10)" & _
");"
Const strSQLAppendBs_c As String = _
"INSERT INTO Foo (MyField1, MyField2) " & _
"SELECT Bar.MyField1, Bar.MyField2 " & _
"FROM Bar " & _
"WHERE Bar.MyField2 Like 'B*';"
If Not TableExists("foo") Then
CurrentDb.Execute strSQLCreateFoo_c
End If
CurrentDb.Execute strSQLAppendBs_c
End Sub
Private Function TableExists(ByVal name As String) As Boolean
On Error Resume Next
TableExists = LenB(CurrentDb.TableDefs(name).name)
End Function
【讨论】:
为什么要创建一个表?如果是用于临时数据存储,那很好,否则通常不需要。
请参阅我网站上的 TempTables.MDB 页面,该页面说明了如何在您的应用中使用临时 MDB。 http://www.granite.ab.ca/access/temptables.htm
【讨论】: