SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SET IDENTITY_INSERT equivalent in Access


SET IDENTITY_INSERT equivalent in Access

Author
Message
IT researcher
 IT researcher
SSChasing Mays
SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)SSChasing Mays (628 reputation)

Group: General Forum Members
Points: 628 Visits: 1798
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.
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27402 Visits: 17557
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 Modens 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)
WendellB
WendellB
SSC Eights!
SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)

Group: General Forum Members
Points: 800 Visits: 1762
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!
lshanahan
lshanahan
SSChasing Mays
SSChasing Mays (658 reputation)SSChasing Mays (658 reputation)SSChasing Mays (658 reputation)SSChasing Mays (658 reputation)SSChasing Mays (658 reputation)SSChasing Mays (658 reputation)SSChasing Mays (658 reputation)SSChasing Mays (658 reputation)

Group: General Forum Members
Points: 658 Visits: 436
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.
Jay Johnson-376926
Jay Johnson-376926
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 5
The following worked for me:

Get users out of system
Backup Access (back-end if split) database
Open (back-end) Access database and go to Relationships.
Document any relationships (and rules) for the subject table
Remove relationships
Run command in VBA window:
CurrentDb.Execute "ALTER TABLE [Project Table] ALTER COLUMN ProjectNumber COUNTER(20170001,1)"
where 20170001 will ne the NEXT value of auto-number.
Replace Relationships!

I did not experiment with trying to just modify relationships or using a finer scalpel..

Hope it helps someone.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search