Solved

Weird Problem with SQL CREATE TABLE?

Posted on 2002-07-16
11
180 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

760 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

19 Experts available now in Live!

Get 1:1 Help Now