I have in Microsoft Access a linked table to an ASE Server.
On the server side, the table has no primary key or identity columns.
And has a trigger on insert that validates new entries, so that when the entry is not validated it deletes the entry from the table and writes to "table"_ERR to let the users know what error was produced.
When linking it to Access a composite key is created using 10 columns.
I have this same setup in 10 different tables (all with triggers all linked to Access)
In this particular table when trying to insert/append records to the table through Access i always get the error message:
Single-row update/delete affected more than one row of a linked table. Unique index contains duplicate values.
This error occurs when both table and table_ERR are empty and i'm only trying to insert 1 record.
If I disable the trigger i have no problem inserting records through Access
I have similar triggers in other tables that are working correctly.
What can be causing this issue and does anyone know how to solve this?
I have read that MS Access can mess up the ##identity, even so none of the solutions presented online seem to work.
links : https://groups.google.com/forum/#!msg/microsoft.public.sqlserver.programming/McHdRpPKMhs/SlyObU8w7JMJ
Stop Access from using wrong identity when appending to linked table on SQL server
Thanks in advance.
EDIT: if i try to insert the records directly from a management software (like Aqua Data Studio) there are no erros
Without knowing more specifics about your data itself, it is difficult to say why this might be happening.
However, it sounds like in this specific instance for this specific linked table, your 10 columns are not unique enough to prevent non-distinct rows from being selected.
Suggested fixes:
Add a primary key. Honestly, probably the best and easiest choice.
If for some reason you cannot add a new column to (or alter) your table; you may be able to re-link your table, and re-choose your 10 columns so that they are more unique.
Beyond that, I think we would need more information.
Just out of curiousity, what is the reason for having no key?
Let's say I have an old .SQL dump and since it was created, I have changed the table schema.
I could be running:
INSERT INTO `ec_product_campaign_relations` (`campaign_id`, `product_id`, `product_qty`) VALUES (30,28,1),(30,27,0),(30,31,0),(30,30,0);
But if column product_qty does no longer exist, the line will not get inserted.
How can I force the line to get inserted anyways and ignore that the column does not exist?
EDIT: It should mention I'm working in PHP and it is script used to sync table shema... So no "manual" control over this.
Since editing all your SQL dump won't be trivial, I suggest you to add the column to your table, make the import, then delete the column.
You might want to create a new database for this import and restore the dump as-is. Then, once you've got a handle on what changes have been made by comparing the schema in one to the new one, create a series of ALTER TABLE statements that bring it in sync.
I tend to record these in a text file in case I need to replay them later, and also keep them as a list of what's changed. You may have to do this more than once, so notes help.
Then, once you've cleaned them up to be column-compatible, dump this database table-by-table, and restore into the other as required.
In phpMyAdmin, I wanted to copy a database to another name so I would effectively have 2 databases exactly the same. One as my oringinal and another for testing on the staging website site that I have.
There are three main options
structure only
structure and data
data only,
I need structure and data, however there are more checkbox options below;
CREATE DATABASE before copying //was checked by default
Add DROP TABLE / DROP VIEW
Add AUTO_INCREMENT value //was checked by default
Add constraints
Switch to copied database
What does "ADD AUTO_INCREMENT value" and "Add constraints" mean and if I copy structure and data doesnt any fields with AI get copied?
When you export / import a database including structure and data, phpmyadmin restores it in the same state as it was. The same applies when you copy the database.
Add AUTO_INCREMENT value simply set the auto_increment value correctly so you can correctly use the restored database. This is necessary in case phpmyadmin does some kind of bulk insert where the auto_increment is not incremented on each insert.
This is also needed to set the correct value, as you can insert then delete some data in your table, so in order to keep the data consistency you have to keep not only the exact ID but also not use an ID which had been used by an old row.
The Add constraints does exactly what it means, i.e. it restores all the constraints on the table in your database. This is also required if you want a complet dump.
For what you are trying to do, maybe a database replication would be better.
You can find information on replication here and here.
If the "Add AUTO_INCREMENT value" and "Add constraints" checkboxes are checked, the new table should have the same next autoindex and constraints like the copied table. All the fields with AI get filled
"Add AUTO_INCREMENT" is keep doing auto increment in new copied database. if we unchecked then it will stop auto increment from that fields. so, if we want maintain auto increment into new database as well then keep checked "Add AUTO_INCREMENT"
While Altering a table in mysql to Add a new Column I am getting Fatal Error Occurred.. I ve seen the relevant answers for this question where I found an Answer like :--
Make a new table with the same structure.
Add the column to the new table.
Insert the data from the old table into the new table.
Rename the old table to old.bak
Rename the new table to the old table.
If all went well, delete the old.bak.
But my original table contains some triggers , indexes, etc.
My question is
"Can I write my Alter Script in any diff. way to overcome this fatal Error" ?
My concern is related to MYSQL, but any other RDBMS related answers also fine...
This is MySQL specific: You can use a combination of [SHOW CREATE TABLE tabname][1] and [SHOW TRIGGERS WHERE Table = 'tabname'][2] to regenerate the table and triggers. You probably don't want the triggers firing when you are copying the rows. Also, if the table is of a significant size or you have a high enough rate of change, you probably want to prevent writes to it during the copy.
Sequence of steps:
Prevent writes to table (optional)
Create new table with SHOW CREATE TABLE output.
Apply schema changes.
Copy data from old table to new table.
Apply triggers from SHOW TRIGGERS output.
Swap old and new tables.
Hope this helps.
I want to globally replace all instances of my site url in the Wordpress MySQL database with a new site url. To do that, I'm using phpMyAdmin to export the database to a .sql file, then doing a global replace in a text editor, then using phpMyAdmin to import the .sql file.
During the import, I'm encountering a duplicate entry for primary key error. Trying to debug this, I exported the file, then imported the identical file, making no changes and I still get the same error.
I appreciate any help solving this.
--
-- Dumping data for table `wp_comments`
--
INSERT INTO `wp_comments`
(`comment_ID`, `comment_post_ID`, `comment_author`, `comment_author_email`
,`comment_author_url`, `comment_author_IP`, `comment_date`, `comment_date_gmt`
,`comment_content`, `comment_karma`, `comment_approved`, `comment_agent`
,`comment_type`, `comment_parent`, `user_id`)
VALUES (1, 1, 'Mr WordPress', ''
,'http://wordpress.org/', '', '2011-04-28 00:49:55', '2011-04-28 00:49:55'
,'Hi, this is a comment.<br />To delete a comment,
just log in and view the post's comments.
There you will have the option to edit or delete them.'
, 0, 'post-trashed', '', '', 0, 0 ) ;
MySQL said:
#1062 - Duplicate entry '1' for key 'PRIMARY'
The original data is still in the database.
If you were working manually you'd send a UPDATE rather than INSERT query with the new values, but since you're doing a batch import, it may just be better to wipe the existing table clean before the import.
DELETE FROM `tblName`;
Be sure to back-up your data, first.
To avoid duplicates you have to use UPDATE instead of INSERT statements. To achieve this in phpMyAdmin, follow these steps:
Select your database in the tree.
OPTIONAL. Go to "Search" tab and search for string you want to replace in all tables. If string is found in several tables only, note their names. This will help to speed up process by updating only the tables which needs updating. This my be important if you have lot of data.
Go to "Export" tab.
In the "Export method:" select "Custom".
OPTIONAL. If you noted the tables which need updating in step 2 above, then in the "Table(s):" section, click "Unselect all" and then select only the tables which need to be updated.
Scroll down to "Data creation options" section, and in the drop
box labeled "Function to use when dumping data:" select "UPDATE"
(default is "INSERT").
Click "Go".
Open the downloaded SQL dump file.
IMPORTANT! Save the file with a new name for backup purposes before any changes are made.
Use Search & replace function of your editor to change what you want. Then save the file.
In phpMyAdmin go to "Import" tab.
In the "File to import:" section click the "Choose file" button and
browse for the edited file. Click GO
You are ready! To check if everything is OK, search the database second time (repeat step 2). You should not find any tables containing your old string.
If you're exporting, that means that the main content stays in the database. So, when you try to insert a new row with the same PRIMARY KEY, which are always UNIQUE, you'll get an error.
Solution: You must delete the row from the table that has the same comment_ID.
You must open the PHPMyAdmin and go your table page, and check the row with the ID you want. In this case is 1, which means that it is probabily in the first results page of your table listing. Just click on the red X which appears in the row.
This could also be done by SQL, which could be simple too.
DELETE FROM `wp_comments` WHERE `comment_ID` = 1 LIMIT 1
For this, just select your database in PHPMyAdmin and go to the SQL tab, and insert the code above in the text area.
Had the same problem and error number. Deleted the database, recreate with no tables, and import the changed export file worked for me.
The problem is related with your file - you are trying to create a DB using a copy - at the top of your file you will find something like this:
CREATE DATABASE IF NOT EXISTS *THE_NAME_OF_YOUR_DB* DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci;
USE *THE_NAME_OF_YOUR_DB*;
and I'm sure that you already have a DB with this name - IN THE SAME SERVER - please check, because you are trying to overwrite!! Just change the name OR (better) ERASE THIS LINE!
Since you already have that record there, you can just update the record rather than inserting. It would go something like this.
UPDATE `wp_comments`
SET 'comment_author_url' = 'YOUR NEW ADDRESS'
WHERE `comment_ID` = 1
Just update every instance of your old address using this method. You can search through all of all posts by saying "WHERE 'comment_author_url' = 'YOUR OLD ADDRESS'"
If all you want to do is replace your URL, I believe this is all you must do:
Update `wp_comments` Set
`comment_author_url` = 'http://wordpress.org/'
Where `comment_author` = 'Mr WordPress'
Just type the above SQL into PHPMyAdmin's SQL box and execute.
NOTE: First make sure you have a backup. And there's no need to do all that export and import stuff :)
Change to code to
INSERT .... (what you already have)
ON DUPLICATE KEY UPDATE;
This will fix your problem with a minimum of fuss, whilst still inserting new rows.