Re: Drop Primary Key with SQL/VBA
From: gorden blom (gordenblom_at_hotmail.com)
Date: 04/07/04
- Next message: Dunderhead: "Find Matching records"
- Previous message: Chris2: "Re: Stock Transaction Query"
- In reply to: Gary Walter: "Re: Drop Primary Key with SQL/VBA"
- Next in thread: Gary Walter: "Re: Drop Primary Key with SQL/VBA"
- Reply: Gary Walter: "Re: Drop Primary Key with SQL/VBA"
- Reply: Gary Walter: "Re: Drop Primary Key with SQL/VBA"
- Messages sorted by: [ date ] [ thread ]
Date: 6 Apr 2004 23:22:59 -0700
Gary,
Thanks for your replay! Your code works for me too. I've rebuild my
table and everything works fine now. I'm still wandering why it didn't
work earlier, when I've found the error I will post back with the
anwser.
This field had no relationships with other, and it was inside my
access DB. Thanks for your help in the last couple of day's I've
appriciated your help.
Gorden Blom
"Gary Walter" <garylwpleasenospam@wamego.net> wrote in message news:<uBS4PtuGEHA.3856@TK2MSFTNGP12.phx.gbl>...
> "gorden blom" <gordenblom@hotmail.com> wrote in message
> news:8c25c8c2.0404042237.725633cd@posting.google.com...
> > Hi,
> >
> > Thanks for all the replies. I know the name of the constraint, it's
> > been given the same way, as in your example. When I dropped the
> > constraint there still is the primary key on that field. I can't drop
> > this field until I've removed the primary key.
> >
> > When I try to drop the field I get the following error:
> >
> > Error 3280:
> >
> > Cannot delete a field that is part of an index or is needed by the
> > system.
> >
> > I think it can only be done in the following way:
> > 1. Drop the constraint(done that)
> > 2. Drop the primary key
> > 3. Drop the field (can only be done if I first do nr. 2)
> >
> Hi Gorden,
>
> If I save the following in a module:
>
> Public Sub CreateTable()
> Dim strSQL As String
>
> strSQL = "CREATE TABLE tblCustomer " _
> & "(CustomerID INTEGER CONSTRAINT PK_CustomerID PRIMARY KEY, " _
> & "Address TEXT(50), " _
> & "City TEXT(50), " _
> & "State TEXT(2), " _
> & "Zip TEXT(10));"
> CurrentDb.Execute strSQL, dbFailOnError
>
> End Sub
>
> Public Sub DropPK()
> Dim strSQL As String
>
> strSQL = "ALTER TABLE tblCustomer " _
> & "DROP CONSTRAINT PK_CustomerID;"
> CurrentDb.Execute strSQL, dbFailOnError
>
> End Sub
>
> If I run the sub CreateTable(),
> then open new tblCustomer in design view,
> with CustomerID selected,
> I see:
>
> a "key" beside CustomerID
>
> and in "General":
>
> Field Size Long Integer
> Decimal Places Auto
> Required No
> Indexed Yes (No Duplicates)
> (all other rows have no value)
>
> Then, if I run the sub DropPK(),
> then open tblCustomer in design view,
> with CustomerID selected,
>
> I see:
>
> no "key" beside CustomerID
>
> and in "General"
>
> Field Size Long Integer
> Decimal Places Auto
> Required No
> Indexed No
> (all other rows have no value)
>
>
> **And I can delete the field CustomerID.***
>
> So...why does this not work for you?
>
> What is the difference in the "General" tab
> before and after you run your drop constraint SQL?
>
> Did you create the constraint in SQL
> so you for sure know its name?
>
> Is the field also part of a relationship?
>
> Is this field in an Access table (or some
> other db)?
- Next message: Dunderhead: "Find Matching records"
- Previous message: Chris2: "Re: Stock Transaction Query"
- In reply to: Gary Walter: "Re: Drop Primary Key with SQL/VBA"
- Next in thread: Gary Walter: "Re: Drop Primary Key with SQL/VBA"
- Reply: Gary Walter: "Re: Drop Primary Key with SQL/VBA"
- Reply: Gary Walter: "Re: Drop Primary Key with SQL/VBA"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|