Solved

Weird Problem with SQL CREATE TABLE?

Posted on 2002-07-16
11
184 Views
Last Modified: 2010-05-02
Hello, I am working on a program that basicly creates a database and I am having problems using the SQL CREATE TABLE to make the tables. The database that I am using is Access (DAO 3.6). Here is a piece of code:
 Set DB = engine.CreateDatabase(txtDatabasePath.Text, dbLangGeneral)
 
  DB.Execute "CREATE TABLE keys (test varchar(10) NOT NULL, ver varchar(1) default 'A', answers varchar(60) NOT NULL)TYPE=MyISAM;", dbFailOnError
  DB.Execute "CREATE TABLE answers (sID varchar(2) NOT NULL, pID varchar(3) NOT NULL, comp_ans varchar(60) default NULL, math_ans varchar(60) default NULL, sci_ans varchar(60) default NULL)TYPE=MyISAM;", dbFailOnError

Is there something wrong that I am missing. I thought for sure that you could do this, but maybe I was mistaken. Thanks a lot for the help.
~evlich
0
Comment
Question by:Evlich
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 32

Expert Comment

by:bhess1
ID: 7157738
The 'TYPE=MyISAM' is not an Access command - it is specific to MySQL.  Try removing that first.

Default is also problematic in Access.  As of Access 97, Default is not accepted as a legal command, but this may have changed in Access 2000.

The default NULL statements can be left off - Access will default to NULL for fields.
0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7157788
Do you have to use DAO?  It's much easier using ADO and ADOX.  I can even supply an example if you want to get out of the dark ages...I mean away from DAO.
0
 
LVL 1

Author Comment

by:Evlich
ID: 7157946
Well the defaul let me get through those first tow lines, but I have several more line that it is getting trapped on. Can you use tinyint and stuff like that? Here is the new line that the program gets trapped on:
  DB.Execute "CREATE TABLE prog_submissions (tID TINYINT(2) NOT NULL, problem varchar(5) NOT NULL, correct TINYINT(1) NOT NULL, time TIME NOT NULL, er_code tinyint(1));", dbFailOnError
There are still a few lines after that, but I think that this has all the stuff that is used later on. Thanks a lot.
~evlich
P.S. I would appreciate some links to pages for ADO, I have never actually used it, and it might be better for this.
0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7157974
Her's a module to create a DB:
Public Function gfAB_CreateDB(asDB as string) As Boolean
    Dim adoxCat     As ADOX.Catalog
   
    On Error Resume Next
   
    If Len(Dir(asDB)) > 0 Then Kill asDB
   
    On Error GoTo Syntax_Error
   
    Set adoxCat = New ADOX.Catalog
   
    adoxCat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & asDB
   
    Set adoxCat = Nothing
    gfAB_CreateDB = True
   
Exit_Sub:
    Exit Function
   
Syntax_Error:
    gfAB_CreateDB = False
    Resume Exit_Sub

End Function

Here's a function to create a table:
Public Function gfAB_CreateTable(asDB as string) As Boolean
    Dim adoxCat     As New ADOX.Catalog
    Dim adoxTab     As New ADOX.Table
    Dim adoxCol     As ADOX.Column
   
    On Error GoTo Syntax_Error
   
    adoxCat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & asDB
   
    adoxTab.Name = "TableNameHere"
   
    Set adoxCol = New ADOX.Column
    adoxCol.Name = "ColNameHere"
    adoxCol.Type = adVarWChar
    adoxCol.DefinedSize = 2
    adoxCol.Attributes = adColNullable
    adoxTab.Columns.Append adoxCol
   
    adoxCat.Tables.Append adoxTab
   
    Set adoxCol = Nothing
    Set adoxTab = Nothing
    Set adoxCat = Nothing
   
    gfAB_CreateTable = True
   
Exit_Sub:
    Exit Function
   
Syntax_Error:
    gfAB_CreateTable = False
    Resume Exit_Sub

End Function


The above would create a table with one varchar(2) column.

Hope that helps.
Steve

PS  Don't forget to add a reference to the ado ext.
0
 
LVL 32

Expert Comment

by:bhess1
ID: 7158004
Tinyint(2) - I assume that this is a 2 byte integer?

Here are some Access SQL Conversions for you:

4 byte integer, usually INT or INTEGER in most SQL dialects.  Access SQL = INTEGER

2 byte integer, usually smallint in most SQL dialects.  Access SQL = smallint or integer2

1 byte integer, usually tinyint in most SQL dialects.  Access SQL = integer1 or byte



0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7158013
nope it will create a varchar(2)
this will creat an integer column:
    adoxCol.Type = adInteger
0
 
LVL 1

Author Comment

by:Evlich
ID: 7158651
Well, that worked, only one more problem, how do you do a date/Time field.
~evlich
0
 

Expert Comment

by:Amitabh
ID: 7158881
Following is a link for creating database through ADOX and learning other features.

http://www.able-consulting.com/ADOX_Faq.htm#Q2

regards,
A. Pandey
0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7159232
I don't know if you are asking me but here's what to use for dates and times:
adoxCol.Type = adDBDate
adoxCol.Type = adDBTime
adoxCol.Type = adDBTimeStamp
0
 
LVL 32

Accepted Solution

by:
bhess1 earned 50 total points
ID: 7159869
For SQL creation, use DATETIME - Alternates are DATE or TIME - all reate an Access DateTime field
0
 
LVL 1

Author Comment

by:Evlich
ID: 7162618
Thanks a lot. I appreciate all the help and suggestions that I was given by everyone. I will take ADO into consideration.
~evlich
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now