views:

126

answers:

2

I want to drop a column from table in access which is the primary key. how can i write a query for this.

+1  A: 

You need to remove the primary key index on the table first in one query:

DROP INDEX PrimaryKey ON Table1

Then you can remove the column in a second query:

ALTER TABLE Table1 DROP COLUMN id
Alistair Knock
i am getting an error message no such index primarykey on table1
tksy
You need to remove any relationship the table is participating in before your remove the PK.
David-W-Fenton
@David W. Fenton: Don't you rather mean "You need to remove any relationship the PK is participating in before your remove the PK"? A SQL foreign key can reference a UNIQUE constraint that is not a PRIMARY KEY. A MS Access 'relationship' doesn't even require a unique constraint (don't believe the message you see when you try to save a table without a PK created via the designer, it lies,it lies).
onedaywhen
A: 

You can get the name of the index in a number of ways.

Dim RS As ADODB.Recordset

    Set RS = CurrentProject.Connection.OpenSchema _
        (12, Array(Empty, Empty, Empty, Empty, "Table1")) ''12=adSchemaIndexes
    RS.Filter = "PRIMARY_KEY = True"
    If Not RS.EOF Then
        Debug.Print RS.Fields("Index_Name")
    End If
End Sub

More here http://stackoverflow.com/questions/1649049/what-is-the-name-of-the-violating-unique-index-constraint-in-dao-ms-access

Remou