Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SET IDENTITY_INSERT equivalent in Access Expand / Collapse
Author
Message
Posted Wednesday, August 21, 2013 7:49 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, July 25, 2014 10:34 PM
Points: 265, Visits: 1,714
In sql server i can explicitly insert value to a identity column of a table by using SET IDENTITY_INSERT ON. For an Access database i am using Autonumber column datatype. For this column i am not able to insert value of my own.

This link shows how the SET IDENTITY_INSERT setting can be used to fill a gap in the identity values caused by a DELETE statement.

Now how the same can be done for Access database.If i delete a row having some autonumber,then in future i want to insert same autonumber value.But i am not able to use SET IDENTITY_INSERT for access. So how the same can be done in Access.
Post #1486718
Posted Wednesday, August 21, 2013 7:58 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:36 PM
Points: 13,111, Visits: 11,946
I don't think you can do that in Access. If you are using an autonumber why does it matter if there is a gap anyway? This is perfectly normal because when rows get deleted it leaves a gap.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1486727
Posted Wednesday, August 21, 2013 8:52 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, April 17, 2014 6:41 AM
Points: 139, Visits: 509
Sean is absolutely correct - there is no easy way to do that in Access, and in general you shouldn't need to. Access treats autonumber fields as something the user cannot edit. The theory is that their only purpose is to ensure uniqueness.

That said, if you really have to do that, you can copy the autonumber contents into a new Long Integer field that is not an autonumber. Then you delete the autonumber field from your table, add the record that you want and assign it the missing number in the sequence, and finally change the design of the new field to be an autonumber. Then rename the field to be the same as the field you deleted.

If you do that very often you will decide it's a real pain. Alternatives - never allow a record to be deleted, and use a logical delete instead, or move your tables (and some of your fundamental queries) to a SQL Server back-end.


Wendell
Colorful Colorado
You can't see the view if you don't climb the mountain!
Post #1486758
Posted Thursday, August 22, 2013 10:15 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 6:11 AM
Points: 128, Visits: 240
While there isn't an IDENTITY_INSERT equivalent in Access this link gives some options using make-table and append queries.

____________
Just my $0.02 from over here in the cheap seats of the peanut gallery - please adjust for inflation and/or your local currency.
Post #1487392
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse