Inserting Records into ASE linked table results in single-row update/delete affected more than one row of a linked table - database

In Microsoft Access 2016 i have a link to an ASE table trough the Adaptative Server Enterprise ODBC driver.
The table is used only has a data pass table for database admins
On the server side the table has no indexes, primary keys or foreign keys
When linking the table in access, it always asks you to identify the primary key/keys in order to be able to insert records into it.
In Microsoft Access 2010 they had it working by identifying 10 fields as primary keys just so that records could be inserted from access
In Micrososft Access 2016 i am getting the error:
Single-row update/delete affected more than one row of a linked table.
Unique index contains duplicate values. (Error 3362)
Is there a way to allow access to insert records into this table without declaring a primary key, since the server table has none?
Thanks in advance

Related

SQL Server : Relationships

I'm using SQL Server 2019 for my project that is a Library management.
I was going to make a relationship from tblServices to tblCustomers that would get CustomerName from tblCustomer and set it into tblServices field CustomerName.
However when I was going to save the tables SQL Server prevent that and shown this error:
Unable to create relationship 'FK_tblServices_tblCustomers'.
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_tblServices_tblCustomers". The conflict occurred in database "Library_DB", table "dbo.tblCustomers", column 'CustomerName'.
I guess it tells I'm making a duplicate relationship on a same property. But I've checked it and it was just one relationship on CustomerName.

Cannot create a relation between two tables with three primary keys

I recently used Microsoft SQL Server Migration Assistant for Oracle to convert an Oracle database to a SQL Server database through a two-pass approach.
There is are two tables, BILL_INFO and BILL_INFO_DETAIL, that are supposed to have a master-detail relation through composite PK. However, when I try to create that relation, I get this error:
'BILL_INFO' table saved successfully 'BILL_INFO_DETAIL' table
- Unable to create relationship 'FK_BILL_INFO_DETAIL_BILL_INFO'. The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
"FK_BILL_INFO_DETAIL_BILL_INFO". The conflict occurred in database
"MyDatabase", table "dbo.BILL_INFO".
The database is plagued with bad data. So I did a basic search in the detail table to find BILL_NUMBER, PAY_MODE_ID, and CASHIER_ID that may not exist in master (one by one) and found two records when searching on BILL_NUMBER. I fixed them and also verified that PAY_MODE_ID and CASHIER_ID were in order.
Still, I cannot create the relation. Same error. Now I wonder if the Tuple is invalid between tables. How do I find a composite key that exists only in details table?
You could check for non-existing values using:
SELECT bill_number, pay_mode_id, cashier_id
FROM Bill_Info_Detail
EXCEPT
SELECT bill_number, pay_mode_id, cashier_id
FROM Bill_Info;
-- and then fix missing data
When using composite key, you need to check all columns as tuple.

Transfer data from one database to another database with different schema

i have problem to Transfer data from one sqlserver 2008 r2 to another sql server 2012 databases with different schema, here is some different scenario,
database 1
database 1 with tables Firm and Client, these both have FirmId and ClientId primary key as int datatype,
FirmId is int datatype as reference key used in Client table.
database 2
database 2 with same tables Firm and Client, these both have FirmId and ClientId but primary key as uniqueidentifier,
FirmId is uniqueidentifier datatype as reference key used in Client table.
problem
the problem is not to copy data from 1 database table to 2 database table, but the problem is to maintain the reference key's Firm table into Client table. because there is datatype change.
i am using sql server 2008 r2 and sql server 2012
please help me to resolve / find the solution, i really appreciate your valuable time and effort. thanks
I'll take a stab at it even if I am far from an expert on SQLServer - here is a general procedure (you will have to repeat it for all tables where you have to replace INT with UID, of course...).
I will use Table A to refer to the parent (Firm, if I understand your example clearly) and Table B to refer to the child (Client, I believe).
Delete the relations pointing to Table A
Remove the identity from the id column of Table A
Create a new column with Uniqueidentifier on Table A
Generate values for the Uniqueidentifier column
Add the new Uniqueidentifier column in all the child tables (Table B)
Use the OLD id column to map your child record & update the new Uniqueidentifier value from your parent table.
Drop all the id columns
Recreate the relations
Having said that, I just want to add a warning to you: converting to UID is, according to some, a very bad idea. But if you really need to do that, you can script (and test) the above mentioned procedure.

Connecting the tables in a database

I have created a simple database in SQL Server Express which consists of three tables: Inventory, Customers, Orders.
I try to connect them in db diagram forcing the primary keys of Inventory and Customers (CarID and CustID) as foreign keys to Orders. However, when I try to save the diagram, I receive an error that does not allow me to save the diagram and link the tables.
The error indicates:
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
"FK_Orders_Inventory". The conflict occurred in database "AutoLot",
table "dbo.Inventory", column 'CarID'.
FK_Orders_Inventory is the connection between Inventory and Orders. What could be a potential cause of the error?
The data currently in the table is probably not conforming to the constraints you have defined.
Make sure the data is consistent with the constraints before adding them.
In this case, one of the foreign keys you are defining fails because the column you are defining it on (in the Inventory table) contains values that do not exist on the referenced column (CarId) in the foreign table.
You have a CarID value in the child table that does not exist in the parent table.

SQL Server merge replication causes foreign key failures

In my application, using SQL Server 2005, I'm having two tables, let's call them Table A and Table B; a foreign key constraint is defined on Table B, referencing the primary-key column in Table A, which is an auto-generated integer ID. I'm running the following simple transaction:
Start transaction
Insert a row to table A
Retrieve the last-generated ID ("SELECT ##IDENTITY ... ")
Insert data to table B, using this ID
Commit
It all works well, until I'm trying to create merge replication (continuous) with another SQL Server 2005. Both publisher and subscriber now fail this transaction when trying to insert data to table B, because of foreign key constraint failure:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_TableB_TableA". The conflict occurred in database "MyDB", table "TableA", column 'ID'.
I was not able to make it work by committing after inserting data to table A. However, after removing the merge replication, everything worked. The database code is written in C++, using ADO.
Is the replication interfering with the transaction anyhow? Any other possible explanation?
Are the Primary Key values on Table A at both server nodes discrete from one another (In other words are you using Identity Range management at each node)?
Also, has the Foreign Key constraint been configured with the Not For Replication property?
I would assume that because your Foreign Key constraint has already been enforced locally at the Publisher, that you do not need to re-check it when merging with the Subscriber.
Looks like the issue is related to the scope of the ##IDENTITY function. When I used LAST_IDENT('TableB') instead, things seem to work.
As described in MSDN:
IDENT_CURRENT returns the last identity value generated for a specific table in any session and any scope.
##IDENTITY returns the last identity value generated for any table in the current session, across all scopes.
SCOPE_IDENTITY returns the last identity value generated for any table in the current session and the current scope.

Resources