tksy
tksy

Reputation: 3529

MS ACCESS How to drop a column with primary key

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

Upvotes: 2

Views: 7490

Answers (2)

Fionnuala
Fionnuala

Reputation: 91356

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 What is the name of the violating unique index constraint in dao / ms-access

Upvotes: 0

Alistair Knock
Alistair Knock

Reputation: 1836

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

Upvotes: 4

Related Questions