Results 1 to 6 of 6

Thread: Access Alter Column to Nullable

  1. #1

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Access Alter Column to Nullable

    Altering a column to not nullable appears pretty straightforward. Altering a column that is required to be not nullable doesn't seem to be possible. There's a lengthy way around that, of course, since I could drop the column then re-add it (or include more steps to add a temporary column, copy values over, then drop the original, rename the new, and go from there.

    That doesn't seem right. So, is there a means to make a non-nullable column nullable in an Access database using a query?
    My usual boring signature: Nothing

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,130

    Re: Access Alter Column to Nullable

    you could try...
    Code:
    ssql = " Alter Table yourTable Alter Column [myColumn]TEXT Null;"
    
    'the Field myColumn is TEXT
    EDIT: just tried that, and sorry that will not work
    back to the drawing board

    EDIT2: this will work, I used DAO in .NET
    Code:
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim AccessDatabaseEngine As New Microsoft.Office.Interop.Access.Dao.DBEngine()
            Dim AccessDatabase As Microsoft.Office.Interop.Access.Dao.Database
            Try
                AccessDatabase = AccessDatabaseEngine.OpenDatabase("E:\Adressen.mdb")
                AccessDatabase.TableDefs("YourTable").Fields("yourColumn").Required = False
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                AccessDatabase.Close()
            End Try
        End Sub
    Last edited by ChrisE; Jul 30th, 2025 at 11:22 AM.
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Access Alter Column to Nullable

    I'm not going DAO for this.

    In fact, I'm not doing anything, because after a bit of study, I realized that the field was never used in any way and no longer has any relevance, so I dropped it entirely. That solved the problem, but did not answer the question, so I'm leaving it open. I did try your first suggestion before I posted this, as it seemed like it should work. As you noted, it did not. I also found the DAO solution, but that's massive overkill to haul DAO out of it's grave for something like this.
    My usual boring signature: Nothing

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Access Alter Column to Nullable

    Yeah... they even say this on their page : https://learn.microsoft.com/en-us/of...oft-access-sql

    "The Microsoft Access database engine does not support the use of ALTER TABLE, or any of the data definition language (DDL) statements, with non-Microsoft Access databases. Use the DAO Create methods instead."

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Access Alter Column to Nullable

    Quote Originally Posted by gigemboy View Post
    Yeah... they even say this on their page : https://learn.microsoft.com/en-us/of...oft-access-sql

    "The Microsoft Access database engine does not support the use of ALTER TABLE, or any of the data definition language (DDL) statements, with non-Microsoft Access databases. Use the DAO Create methods instead."
    What's that got to do with the original issue?
    MS Access-ENGINE doesn't support ALTER TABLE for NON-Access-Databases (e.g. if you have linked NON-Access-Tables)

    Shaggy, have you thought about it that a "NOT NULL" actually is a CONSTRAINT (like UNIQUE)?
    Remember this: https://www.vbforums.com/showthread....ove-Constraint

    EDIT: Found this: https://stackoverflow.com/questions/...lumn-in-access
    Seems you're out of luck.
    Open that Access-DB in Access itself, go to the designer, and change the Required Prop for the Column there.
    It is as it is....
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Access Alter Column to Nullable

    Probably nothing now that I re-read. But Shaggy is still prob out of luck with this one: https://stackoverflow.com/questions/...lumn-in-access

Posting Permissions

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



Click Here to Expand Forum to Full Width