473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

SQL Insert, Autonumber, and End of Table ???

I have created a SQL string the properly inserts a record in the table.
However, the insert does not occur at the end of the table. Instead
it inserts a record after the last record that I viewed. This would be
OK, except it assigns a autonumber to be one greater than the last
viewed record. This causes a duplicate autonumber. I know I can
change the autonumber index (Primary Key) to not allow duplicates.

How can I force the insert to use the highest autonumber + 1? I would
think that this should be handled automatically.

Mar 3 '06 #1
8 15940
Br
pe********@comcast.net wrote:
I have created a SQL string the properly inserts a record in the
table. However, the insert does not occur at the end of the table.
Instead it inserts a record after the last record that I viewed.
This would be OK, except it assigns a autonumber to be one greater
than the last viewed record. This causes a duplicate autonumber. I
know I can change the autonumber index (Primary Key) to not allow
duplicates.

How can I force the insert to use the highest autonumber + 1? I would
think that this should be handled automatically.


Without seeing your code/script or knowing the sequence of events it's hard
to know what the issue is.

You talk about autonumber... is it actually an autonumber field or are you
manually creating your own? There is no way an real autonumber type field
will create a duplicate.

Either make is a real autonumner field, or insert Max([MyField]) + 1 as the
new value.
--
regards,

Br@dley
Mar 3 '06 #2
This is the true autonumber field created by access. I have not changed
it.

Does the "Insert Into" Command append the record at the bottom of the
file, or does it insert anywhere in the file?

Mar 3 '06 #3
This is the true autonumber field created by access. I have not changed
it.

Does the "Insert Into" Command append the record at the bottom of the
file, or does it insert anywhere in the file?

Mar 3 '06 #4
Br
pe********@comcast.net wrote:
This is the true autonumber field created by access. I have not
changed it.

Does the "Insert Into" Command append the record at the bottom of the
file, or does it insert anywhere in the file?

Tried the help file?

"If you append records to a table with an AutoNumber field and you want to
renumber the appended records, do not include the AutoNumber field in your
query. Do include the AutoNumber field in the query if you want to retain
the original values from the field."

--
regards,

Br@dley
Mar 3 '06 #5
I started with the help file. I understand the help data. However,
the issue still exists.
the sql is "Insert into table ( name, address, city ) values ( "XXX",
"YYY", "ZZZ" ).

This command does not use the AUTONUMBER field, called (RcdNumber). It
does not append with a new higher autonumber value. It does replicate
and existing number.

Mar 3 '06 #6
There's something wrong with your db try compact and repair and see if that
fixes it.

--

Terry Kreft
<pe********@comcast.net> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
I started with the help file. I understand the help data. However,
the issue still exists.
the sql is "Insert into table ( name, address, city ) values ( "XXX",
"YYY", "ZZZ" ).

This command does not use the AUTONUMBER field, called (RcdNumber). It
does not append with a new higher autonumber value. It does replicate
and existing number.

Mar 3 '06 #7
On Fri, 3 Mar 2006 12:40:34 +1100, "Br@dley" <cu@dendof.it> wrote:

And put that primary key back! Your "business rule" obviously is that
you don't want duplicates. So let the db engine enforce that rule. If
you ever get a "unique index violation" error, 99.9999% chance it's
your programming error, and an opportunity to improve your code.

-Tom.

pe********@comcast.net wrote:
I have created a SQL string the properly inserts a record in the
table. However, the insert does not occur at the end of the table.
Instead it inserts a record after the last record that I viewed.
This would be OK, except it assigns a autonumber to be one greater
than the last viewed record. This causes a duplicate autonumber. I
know I can change the autonumber index (Primary Key) to not allow
duplicates.

How can I force the insert to use the highest autonumber + 1? I would
think that this should be handled automatically.


Without seeing your code/script or knowing the sequence of events it's hard
to know what the issue is.

You talk about autonumber... is it actually an autonumber field or are you
manually creating your own? There is no way an real autonumber type field
will create a duplicate.

Either make is a real autonumner field, or insert Max([MyField]) + 1 as the
new value.


Mar 3 '06 #8
Thanks for all the input. The key as marked as no duplicate. However,
I deleted the key and the field. COmpressed and reapired, rebuilt the
field and index, did another compress and rebuilt. It all works
correctly . It was apparently a database corruption error.

Mar 4 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
3
by: Ivan Sammut | last post by:
Hi, I have a table which the first field is an autonumber field as is also my keyfield. Now I want to know if it is possible that after I do an insert stament I can get what the value of this...
1
by: Jan | last post by:
I have a table with autoincrement unique ID plus name (required not to be blank) and other fields. I have a list of names in another table and would like to do insert to the name field of the...
7
by: Cindy H | last post by:
Hi I'm having a problem getting the insert statement correct for an Access table I'm using. The Access table uses an autonumber for the primary key. I have tried this: INSERT INTO Tournaments...
10
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be...
2
by: rn5a | last post by:
In a ASP applicatiuon, the FOrm has a textbox & a select list where the admin can select multiple options. Basically the admin has to enter the name of a new coach in the textbox & select the...
4
by: Lyn | last post by:
Hi, Is there an "easy" way to write a full record (all fields) using "INSERT INTO..." into a table which has an AutoNumber field? Normally, to write a full new record I would use: INSERT INTO...
2
by: ramzansadiq | last post by:
Hi guru's, I m unable to find how to Insert a primary key which is also an autonumber field into Table. My query is as below.It is inserting record if i m hardcoding the ID Field. It is VBA Access...
2
by: Ken Foskey | last post by:
I need to trap an insert on an MS access table that uses a generated typed table and row setup. I have to trap the insert and then hook up and get the autonumber value for the insert. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.