Re: Drop Primary Key with SQL/VBA
From: Gary Walter (garylwpleasenospam_at_wamego.net)
Date: 04/05/04
- Next message: Andy_HR: "Re: question ... query and filtering"
- Previous message: James: "Re: Totals Query"
- In reply to: gorden blom: "Re: Drop Primary Key with SQL/VBA"
- Next in thread: gorden blom: "Re: Drop Primary Key with SQL/VBA"
- Reply: gorden blom: "Re: Drop Primary Key with SQL/VBA"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 5 Apr 2004 03:46:24 -0500
"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: Andy_HR: "Re: question ... query and filtering"
- Previous message: James: "Re: Totals Query"
- In reply to: gorden blom: "Re: Drop Primary Key with SQL/VBA"
- Next in thread: gorden blom: "Re: Drop Primary Key with SQL/VBA"
- Reply: gorden blom: "Re: Drop Primary Key with SQL/VBA"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|