简体   繁体   中英

Setting primary key for SQL Server view linked to Access front end

I have a SQL Server view linked to an Access front end. The view is updatable in SQL Server Management Studio, but not currently updatable through Access. After some research, it seems that I might need to specify the primary key in Access for the view in order for Access to be able to modify records in the view.

I came across this

How to set primary key when linking with CreateTableDef

which shows in the responses a couple of different approaches to setting the primary key. These two approaches are as follows:

CurrentDb.Execute "CREATE UNIQUE INDEX SomeIndex ON vwMyView (PrimaryKeyColumn) WITH PRIMARY".

and

CREATE INDEX <YourIndexName> ON <YourTableName>(<YourFieldName>) WITH PRIMARY

I am confused by the different specification of the "index" and the "field"/"column" names. If the column in my view that I want to be the primary key is myID, does that get specified as the index or field, or both? If not both, what is the other name?

Is the period at the end of the first approach a typo? I haven't seen that before.

CREATE INDEX <YourIndexName> ON <YourTableName>(<YourColumnName>) WITH PRIMARY
  • <YourIndexName> = Any name you want, this will be used by Access

  • <YourTableName> = The name of your table in Access

  • <YourColumnName> = The name of the column in the table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM