开发者

MS ACCESS How to drop a column with primary key

I want to drop a column from table i开发者_运维知识库n access which is the primary key. how can i write a query for this.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜