Does T-SQL let you do: SET SQL_SAFE_UPDATES = 0; - sql-server-2008

I'm wondering if T-SQL has something like: SET SQL_SAFE_UPDATES = 0;
Or if there is a way to disable safe update mode in Microsoft SQL Server Management Studio?
We are currently trying to delete duplicate records in our table but it has no primary key. I think this is why we are getting the following error:
OLE DB provider "MSDASQL" for linked server "A_LINKED_SERVER" returned message "Key column information is insufficient or incorrect. Too many rows were affected by update.".
The logical solution would be to add a primary / unique key but we need data to be fed in continuously (we're importing data from one database to another) - by adding a primary / unique key, data would stop coming in once a duplicate record exists and this is not what we want to happen.
Hope someone can help!
Thanks

Related

MySQL Auto_Increment trying to automatically insert prior used values

I Use Delphi 10.2, MySQL. I have a table that has about 50,000 records and has an Auto_Increment primary key. It has suddenly, and on it's own with no help from me, started trying to re-insert old key values. As a matter of fact, it started over with the value 1. I have no idea how to fix this and I hope you might be able to help.
Thanks,
Jim Sawyer
If the MySQL table is defined with an auto increment primary key then you should never specify the key value. MySQL should not re-use old key values, but you may want to check if there is any table corruption. You can also reset the table's auto-increment value using an ALTER TABLE command. (There's a tutorial on this here: https://www.mysqltutorial.org/mysql-reset-auto-increment)
You can use the Firedac monitoring to confirm whether or not you are sending the primary key to MySQL - set you connection to be monitored using the FireDAC component - they supply a monitoring tool that you can setup to see all of the SQL being transferred. Normally the Firedac layer would do an insert with no primary key and then use LAST_INSERT_ID to update the TField to have the actual value inserted.
If you are sending the wrong key then alter your logic so you don;t send the primary key on an insert.
you can reset the autoincrement value to any value you want with the following command
ALTER TABLE <table_name> AUTO_INCREMENT = <new value>;
so if new value is 100, the next inserted record receives a value of 100.

Update all rows except identity column in Access 2013

I have a form in Access linking to a SQL Server table. This table has a UID. After I create a new record in Access, it tries to update the table (including the UID) and gives me the error:
Explicit value must be specified for identity column in table 'TableName' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column.
Now, I understand why this error is occurring but am not sure how to get around it. I can't change IDENTITY_INSERT, and the UID column in Access links the form to a subform, so I do need to include it in the form. How do I exclude only the UID column from the ODBC update? I know I can use a macro to explicitly define columns to update, but there must be an easier way. Is there a function like Me!UIDTextbox.Undo I can run in the Before Update event?
Some more detail:
There's no VBA module or query in Access. It's a standard SQL server table and the Access form updates the table on record change (the default for Access). The table is linked with the standard ODBC Database connection, with the UID as primary key.
This may be a global problem with using Identity columns as Primary Keys in Access.
Patch idea and possible workarounds at
Problem with identity fields in MS-Access

Reset Auto_Increment on MySql via MSSQL? I'll even settle for Truncate

I have a MSSQL Server 2008 R2 system that updates various tables on various systems during a nightly process. I have a MySQL linked server that has an Auto_Increment on one of it's tables. This tables contents are deleted and replaced each night. This of course does not reset the increment. I have tried:
ALTER TABLE REMOTEMYSQL...[TableWithAI] AUTO_INCREMENT = 1
And I get:
Incorrect syntax near 'AUTO_INCREMENT'
I can successfully:
delete from REMOTEMYSQL...[TableWithAI]
But obviously that doesn't reset the increment on the MySQL side
I tried:
Truncate TABLE REMOTEMYSQL...[TableWithAI]
and I get:
Cannot find the object "TableWithAI" because it does not exist or you do not have permissions.
But the MySql user that is used in the link has full permissions. How can I ether delete the contents and zero the increment, or zero the increment by itself?
Assuming you have your MySQL already configured as a linked server, you can fire off non-query statements to linked servers with EXEC:
EXEC('ALTER TABLE TableWithAI AUTO_INCREMENT = 1') AT LinkedMySQLServerName;
I believe the query should be in MySQL syntax, but I'm not in a position to test from where I'm at.

Error with inserting into mysql database

I am using cfwheels (coldfusion orm framework).
I recently moved some data from my previous host to a new one. Now I am trying to insert into a table, but am getting an error message: "Error Executing Database Query.
Duplicate entry '13651' for key 'PRIMARY'"
I looked into the database and it appears a record with id 13651 already exists. So I think the problem is with mysql generating the right auto increment value.
It seems Auto_Increment value is damaged or not set to max value in that column. It's possible due to bulk insert.
So as per solution, set the maximum PK value + 1 as new AUTO_INCREMENT value. Now when you insert the records in this table, they will automatically pick the next incremented correctly.
ALTER.TABLE tablename AUTO_INCREMENT = value
Is the rest of the data for that record, and the one you are trying to insert, the same? If you you might just need to tell the ORM to replace that value?
If primary key has auto increment attribute turned on, do not insert it manually. remove that primary key part from your insert query (whatever the syntax according to the taste of your ORM framework).

Troubleshooting MySQLIntegrityConstraintViolationException

I have a closed-source upgrade application which migrates my database from an old format to a new format (creates new tables and migrates data from the old to new tables).
The application crashes with a MySQLIntegrityConstraintViolationException. It doesn't give me the name of the table with the primary key violation or the contents of the broken SQL query.
Is there any MySQL server option that I can switch to give me more troubleshooting information? Maybe the text of the failed query or the name of the primary key constraint which is violated?
You can enable the general log file: http://dev.mysql.com/doc/refman/5.1/en/query-log.html . This way it might be possible to see at which point the server stops processing the queries.
You also can run the MySQL command show processlist to see what queries are being processed at that time.
Also have a look into all other application specific error logs.
A first try could be to disable foreign key checks during migration:
SET foreign_key_checks = 0;
A first guess would be, that the old server supported 0 as Primary Key values, whilst the new one does not.