你能否给出一个与MySQL中的CREATE TABLE IF NOT EXISTS ...
等价的MS Access语句?
类似于这样:
IF <no such table>
CREATE TABLE history(<fields>)
也同样适用。
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