Legacy tables grails mapping issue with SQL Server - sql-server

I have 2 legacy tables into SQL Server:
This is the first one --> http://ur1.ca/hl1mi
This the second table --> http://ur1.ca/hl1mr
An these are my domain classes for these tables
Taladro.groovy --> http://ur1.ca/hl1mw
Proyecto.groovy --> http://ur1.ca/hl1n8
When I try to insert a Taladro into the database using the dinamic scaffolding fails with these error:
ERROR util.JDBCExceptionReporter - Cannot insert the value NULL into column 'proyecto_id', table 'Portal.ORECONTROL.TALADROS'; column does not allow nulls. INSERT fails.
I change the name of the foreign key from id_proyecto to IdMalla as are in the legacy tables (See http://ur1.ca/hl1mw).
I'm using a SQL Server 2008 as Database server

Seems that now you have column proyecto_id in TALADROS table with not-null constraint. In domain object Taladro you have specified association column mapping as 'IdMalla' instead of default 'proyecto_id'.
Obviously that means that column proyecto_id is not filled and since it has not-null constraint, you get this error.

I can resolve the problem renaming the domain classes with name of the tables in the database and changing the name of the foreign key to "IdMalla". Thanks all for the answers

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.

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

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

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.

SQL Server Create multiple foreign keys

The table contains a PRIMARY KEY column and another column which is FOREIGN KEY. This works fine. When I attempt to add another column as a FOREIGN KEY I get the following message:
Link to pic
This is unrelated to the PKs or FKs.
There is a setting in SQL Server 2008 SSSM to prevent table rebuilds via the designer.
Tools..Options..Designers... clear the option “Prevent saving changes that require table re-creation”.

Resources