473,856 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15975
Br
pe********@comc ast.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********@comc ast.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********@com cast.net> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.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********@com cast.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
6305
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 one-to-one relationship but on this occasion I must keep username/password details within a seperate table. Here's the basic specs and database schema: -------------------------------------------
3
1651
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 autonumber field. My problem is that I cannot do a "select (max(field_name))" cause I have multiple users using the same table and I can have an other insert from another user while I'm getting the max field value. Ivan
1
5257
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 other table. How do I do it? I get error messages when trying different approaches. In the end, I removed the unique key/autoincrement, inserted and ID field in the source and then did copy&append records in the edit menu and changed it all back....
7
28762
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 (Tournament, MemberName, Score) VALUES (vtournament, vMemberName, vScore) SELECT ID, Tournament, MemberName, Score FROM Tournament WHERE (ID = @@IDENTITY);"
10
12726
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 certain that MyVar will be set to the key-field value that was created when the Append query ran. Now, there are other ways to do it - I know - that will ensure you 'nab' the correct record. But I was wondering
2
9439
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 soccer clubs which he will be coaching; thus he can select only one soccer club for a new coach or multiple soccer clubs. This is how I am trying it: When this Form will be submitted, the new coaches name will be inserted in a MS-Access DB table...
4
38391
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 VALUES (Value1, Value2, ...); If (say) the first field (Value1) is an AutoNumber, what value can you put that will preserve the auto-increment function?
2
23478
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 Insert into TableName(ID,LoginName,FirstName,LastName) Values(AutoNumber??,'Sam','Sam','Don') Insert into TableName(ID,LoginName,FirstName,LastName) Values(21,'Sam','Sam','Don') plz help me ASAP. Ram
2
1879
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 googled this and cannot find a typed solution to the problem. I either abandon type safety or solve this problem. I have to work around 'Refresh the data table' that is greyed out. Ta Ken
0
9916
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9762
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11057
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10696
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9531
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7094
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5761
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4174
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.