Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post

    Create a new table with fields in a DB. (Access)

    I need the code that will create a new table in a db and also create about 13-15 fields. That I need to be able to rename and change the settings for, like the default value, or number of chars.
    All this is done in the code, I don't need a form to do this.

    Does anyone know how to do this? Or a site that can teach me?

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    Pilipinas
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi

    the typical syntax is as follows. assuming you have a connection object named connObj:

    sqlMakeTable = "create table tableName ([field1] integer, [field2] memo with comp, [field3] text (50))"
    connObj.Execute (sqlMakeTable)

    you can add as many fields as you like, using the same pattern as below:

    [fieldName] datatype (length/precision)

  • #3
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Thank you ReyN, but would you be able to expand "[fieldName] datatype (length/precision)"

    Such as how would I be able to set a default value, or create a primary key. If it wouldn't be a problem for you to expand on it please? And if there is a tutorial you know of that I could look at for more information about this topic, I would love to see it.


    Thank you again, ReyN.

  • #4
    New Coder
    Join Date
    Jun 2002
    Location
    Pilipinas
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    okay, here's an excerpt from the JetSql docs:

    Syntax

    CREATE [TEMPORARY] TABLE table (field1 type [(size)] [NOT NULL] [WITH COMPRESSION | WITH COMP] [index1] [, field2 type [(size)] [NOT NULL] [index2] [, ...]] [, CONSTRAINT multifieldindex [, ...]])

    The CREATE TABLE statement has these parts:

    table - The name of the table to be created.

    field1, field2 - The name of field or fields to be created in the new table. You must create at least one field.

    type - The data type of field in the new table.

    size - The field size in characters (Text and Binary fields only).

    index1, index2 - A CONSTRAINT clause defining a single-field index. For more information on how to create this index, see CONSTRAINT Clause.

    multifieldindex - A CONSTRAINT clause defining a multiple-field index. For more information on how to create this index, see CONSTRAINT Clause.

    ---------------------------------------------------

    A CONSTRAINT clause establishes various restrictions on a field, and can be used to establish the primary key. You can also use the CREATE INDEX statement to create a primary key or additional indexes on existing tables.

    I don't recall having seen a site devoted to JetSql, but I think one good place to start would be the docs itself, which ships free with the MSOffice 2000 discs. It's available as a help file in html format, just search for JETSQL40.chm

  • #5
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    You have lost me.

    I'm going to go look on the internet, hard core, for about 2 hours an try to pick up something. I'll reply with some information that maybe you can sort out for me.

    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •