Adding a new column in Access

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Adding a new column in Access

    Hi,

    Using the following ASP code:

    <%
    UpdateDB("ALTER TABLE tblConfig ADD SIMVersion varchar(10) NULL AFTER
    Version" )

    ' Subroutine to update the database and check for any errors that
    occured
    Sub UpdateDB(strSQLCommand)
    If Not Application("Debug") Then
    On Error Resume Next
    End If
    If Not blnError Then
    cnnDB.Execute (strSQLCommand)
    If Err.Number <> 0 Then
    blnError = True
    intErrorNum = Err.Number
    strErrorDesc = Err.Description
    strErrorSrc = Err.Source
    strErrorCmd = strSQLCommand
    Err.Clear
    End If
    End If
    End Sub
    %>
    .... results in the error msg:

    Number: -2147217900
    Source: Microsoft JET Database Engine
    Description: Syntax error in ALTER TABLE statement.

    Ideally, I want to add the new column AFTER a specific column. I note
    you can do this in Fox Pro, MySQL, so thought I could do it in ASP for
    Access or SQL Server ?

    Peter

    Peter Richards Guest

  2. Similar Questions and Discussions

    1. adding on a column...
      How do I make a text box two columns? When I use the create guides feature, the text does not reflow. ( typed in rows 1 and columns 2 ) What am...
    2. adding a column with data
      How do I add a new column with data to an existing table, ensuring correct record matching, using SQL? Situation: I have a table named...
    3. adding column values
      My problem is how to add dataset component given column values (number values) - for example values from PRICE column to have a total amount...
    4. Adding a select column...
      Hi folks, I am aiming to create a "select" column that is unbound on datagrid whose other columns are all data bound. The idea is to let the...
    5. Convert an MS Access Yes/No column to a checkbox column in C# datagrid
      Currently I have a datagrid displaying the multiple columns of data (text and numerical) found in a table in MS Access. In the Access table,...
  3. #2

    Default Re: Adding a new column in Access

    I'm sure someone will correct me if I'm wrong, but I don't believe you can
    specify "after columnname" when you add a column in Access. It'll just get
    added to the end. So, this would work, although it won't do exactly what
    you want.

    UpdateDB("ALTER TABLE tblConfig ADD SIMVersion varchar(10) NULL" )

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "Peter Richards" <jehoshua@my-deja.com> wrote in message
    news:8ttbivkppd2ehscto52l50a5d6uuck9c12@4ax.com...
    > Hi,
    >
    > Using the following ASP code:
    >
    > <%
    > UpdateDB("ALTER TABLE tblConfig ADD SIMVersion varchar(10) NULL AFTER
    > Version" )
    >
    > ' Subroutine to update the database and check for any errors that
    > occured
    > Sub UpdateDB(strSQLCommand)
    > If Not Application("Debug") Then
    > On Error Resume Next
    > End If
    > If Not blnError Then
    > cnnDB.Execute (strSQLCommand)
    > If Err.Number <> 0 Then
    > blnError = True
    > intErrorNum = Err.Number
    > strErrorDesc = Err.Description
    > strErrorSrc = Err.Source
    > strErrorCmd = strSQLCommand
    > Err.Clear
    > End If
    > End If
    > End Sub
    > %>
    > ... results in the error msg:
    >
    > Number: -2147217900
    > Source: Microsoft JET Database Engine
    > Description: Syntax error in ALTER TABLE statement.
    >
    > Ideally, I want to add the new column AFTER a specific column. I note
    > you can do this in Fox Pro, MySQL, so thought I could do it in ASP for
    > Access or SQL Server ?
    >
    > Peter
    >

    Ray at Guest

  4. #3

    Default Re: Adding a new column in Access

    Yeah, same with Enterprise Manager. Obviously that's executing some t-sql
    that's doing what you want. Hmm, I wonder if there's a T-SQL sniffer that I
    can find. ;] I won't be surpised if someone else posts with a better
    solution that will allow you to insert the column in the position you want.

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "Peter Richards" <jehoshua@my-deja.com> wrote in message
    news:ocvbivgltqscgm303dthemor70bptcek39@4ax.com...
    > Hi Ray,
    >
    > On Tue, 29 Jul 2003 00:49:48 -0400, "Ray at <%=sLocation%>"
    > <myfirstname at lane34 dot com> wrote:
    >
    > >I'm sure someone will correct me if I'm wrong, but I don't believe you
    can
    > >specify "after columnname" when you add a column in Access. It'll just
    get
    > >added to the end.
    >
    > That's a bother. When I'm using Access interactively, in design mode,
    > I can position to a column, and then do an insert, for a new column
    > and specify exactly where to place the column.
    >
    > >So, this would work, although it won't do exactly what
    > >you want.
    > >
    > >UpdateDB("ALTER TABLE tblConfig ADD SIMVersion varchar(10) NULL" )
    >
    > Yes, it does.
    >
    > Thanks,
    >
    > Peter
    >

    Ray at Guest

  5. #4

    Default Re: Adding a new column in Access

    Ray at <%=sLocation%> wrote:
    > Yeah, same with Enterprise Manager. Obviously that's executing some
    > t-sql that's doing what you want.
    Yep - just like in Access, a new table is being created with the desired
    column order, then the data from the old table is moved into the new table
    and the old table is dropped.
    > Hmm, I wonder if there's a T-SQL
    > sniffer that I can find. ;]
    Shouldn't be too hard to find it: it's called SQL Profiler and it can be
    found in your Windows Start menu in the SQL Server program group. :-)

    Actually, there's an easier way. There's a button you can click in the EM
    table designer that allows you to see the script being used to effect the
    change.
    > I won't be surpised if someone else
    > posts with a better solution that will allow you to insert the column
    > in the position you want.
    I would :-)

    Using DAO, there's a property called OrdinalPosition, that sets or reads the
    relative position of the fields in the table. However, this does not affect
    the physical order of the fields: only the order in which the fields will
    retrieved when doing a selstar query, which should not be used in production
    code, anyways, right? :-)

    HTH,
    Bob Barrows


    Bob Barrows Guest

  6. #5

    Default Re: Adding a new column in Access

    It did. Thanks Bob!

    Ray at home
    > "Bob Barrows"
    > HTH,

    Ray at Guest

  7. #6

    Default Re: Adding a new column in Access

    > Using DAO, there's a property called OrdinalPosition, that sets or reads
    the
    > relative position of the fields in the table. However, this does not
    affect
    > the physical order of the fields: only the order in which the fields will
    > retrieved when doing a selstar query,
    Really? Is this true for Access only?


    Aaron Bertrand - MVP Guest

  8. #7

    Default Re: Adding a new column in Access

    Aaron Bertrand - MVP wrote:
    >> Using DAO, there's a property called OrdinalPosition, that sets or
    >> reads the relative position of the fields in the table. However,
    >> this does not affect the physical order of the fields: only the
    >> order in which the fields will retrieved when doing a selstar query,
    >
    > Really? Is this true for Access only?
    I'm 90% sure it's only read/write for Jet databases. As I said, it's a DAO
    property: it is not available in ADOX. I suspect that it will not have any
    effect on queries run by ADO.

    Bob



    Bob Barrows Guest

  9. #8

    Default Re: Adding a new column in Access

    Hi,

    Thanks everyone for your replies. The bottom line is that it can't be
    done in ASP on an Access db.

    Peter

    Peter Richards Guest

  10. #9

    Default Re: Adding a new column in Access

    Hi Aaron,

    On Tue, 29 Jul 2003 09:17:40 -0400, "Aaron Bertrand - MVP"
    <aaron@TRASHaspfaq.com> wrote:
    >Why does it matter where a column sits?
    I simply prefer it that way, as I find once a table gets more than
    about 30 columns, from a design point of view, I would prefer an
    ordered view of columns, it simply makes sense and makes maintenanance
    easier. Being restricted by having to add new columns at the end of
    the table moves away from a structured view of the table, even if the
    'view' is only a logical one, that would help a lot.

    The columns I need to add are adding two more dimensions to a
    hierarchy, therefore (for me) from a design point of view, I prefer to
    "see" all the hierarchy represented, logically at least (physical
    order doesn't concern me) in a meaningful and structured manner.
    >If you want to pull data out of the
    >table with columns in a specific order, list them that way in the SELECT
    >statement. You shouldn't care about the physical structure... but if you
    >want to do it that way, you can do what SQL Server, and surely Access, do:
    >create a dummy table with the new column in the correct place, move all the
    >data, disable constraints, swap table names, re-enable constraints, and drop
    >the original table. Yeah, that sounds like fun.
    Yes, rather a painful exercise indeed.

    Peter

    Peter Richards Guest

  11. #10

    Default Re: Adding a new column in Access

    > >Why does it matter where a column sits?
    >
    > I simply prefer it that way, as I find once a table gets more than
    > about 30 columns, from a design point of view, I would prefer an
    > ordered view of columns, it simply makes sense and makes maintenanance
    > easier.
    Shouldn't you have designed the table from the ground up? As soon as you
    start adding columns on the fly after the fact, you can smell lack of good
    design... also, once a table gets more than about 30 columns, I think it
    has too many columns and some normalization may be in order...


    Aaron Bertrand [MVP] Guest

  12. #11

    Default Re: Adding a new column in Access

    Hi,

    On Tue, 29 Jul 2003 21:49:32 -0400, "Aaron Bertrand [MVP]"
    <aaron@TRASHaspfaq.com> wrote:
    >Shouldn't you have designed the table from the ground up?
    Yes, I wish I had have, but I'm making changes to someone elses
    design, a GNU product. The changes I'm making have been requested by
    many people for a year or more, so they (the changes) are long
    overdue. But hey, you get what you pay for. :)
    >As soon as you
    >start adding columns on the fly after the fact, you can smell lack of good
    >design... also, once a table gets more than about 30 columns, I think it
    >has too many columns and some normalization may be in order...
    I agree.

    Peter

    Peter Richards Guest

  13. #12

    Default Re: Adding a new column in Access

    > Have you never worked in a changing environment?

    Uh, yes. Currently, in fact.


    Aaron Bertrand - MVP Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139