I have some service which communicate with a central Core-service. Every time service pass Reference Id to Core-service and Core service check the duplicate data and store Reference Id along the service request. Now I checking the duplicate data from DB table .Which is too much time consuming. The Reference Id is generated in service. Reference Id cant be generated from one point in this case.
1.How to check duplicate data with less time lose ?
2.Do I need any NoSQL db for Reference Id check ?
or any thing else ?
Following query will return the duplicate reference Ids in the table.
SELECT referenceId, COUNT(referenceId)
FROM table
GROUP BY referenceId
HAVING COUNT(referenceId) > 1
Related
I have the following issue in a copy activity:
"Code": 23605,
"Message": "ErrorCode=DynamicsOperationFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Dynamics operation failed with error code: -2147088238, error message: A record that has the attribute values SAP Client, SAP System Id, OrderPOS-ID, Order ID, SAP Module, Account Assignment ID already exists. The entity key Purchase Order Atl Key requires that this set of attributes contains unique values. Select unique values and try again..,Source=Microsoft.DataTransfer.ClientLibrary.DynamicsPlugin,''Type=System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]],Message=The creator of this fault did not specify a Reason.,Source=Microsoft.DataTransfer.ClientLibrary.DynamicsPlugin,'";
I'm using a dynamic query(with a store procedure) and load that based on config table where i have all entities to load. And Recently we start to get this error messages for some countries(but there's no pattern). The entity in this case is Purchase Orders and the processes load part of the data to dynamics, but some countries are failing. I've already checked all possible duplicates and I didn't find none using the keys presented in message above;
This fields are defined as alternatekeys on dynamics in order to avoid duplicates, and the alternatekey are composed with: SAP Client, SAP System Id, OrderPOS-ID, Order ID, SAP Module, Account Assignment ID;
In order to make our process faster I separate PO(PurchaseOrders) in 2 view: (1)Purchase_Order_master : basically copy to dynamics new records with all keys and after this first view run we have the (2)view that got all attributes and do the upsert of all values that suffered some update on source side.
In this 2 view we have the following field in common, these are the only fields in common
sie_purchaseordersid(uniqueidentifier, null)
Executionid(uniqueidentifier, not null)
Hashkey(varbinary(32), not null)
The fields that compose the hashkey are the same that we can find on the alternate key
,HASHBYTES('SHA2_256', CONCAT(SAPSYSID,SAPMOD,MANDT,EBELN,EBELP,TRY_CONVERT(NVARCHAR(255),TRY_CONVERT(INT,ZEKKN)))) HashKey
I don't have more ideas, and i hope one of you already tackled a similar issue in a passed and can provide some help.
Thanks in advance
I've try to find duplicates based on the fields that were mention in log message, but i didn't find nothing;
We use GeneralDetailReportQuery to get customer "transactions" from QuickBooks desktop and save them to a mssql table. Query is called passing the From/To Date filter params to get changes only. We try to get report changes each day and keep our table in sync with QB data. TranId, customer ListId and TranType seem to be those fields which can uniquely identify each record returned by Report query. Problem starts to happen when users change one of those key fields, customer ListId for example.
It must have been a change of a customer in a transaction... ?
Anyway, how to keep data in sync, does report have some kind of primary key field, which is not changed and can be use to track changes ?
Thanks,
Slava
I have this situation :
Table : Article
Id
name
category
.........................
Table : Services
id
name
nr
value
Table : Sell_item
Id
item_id
quantity
price
value
Now the problem is this : The field Item_id on the sell_item table can be the id for an Article or a Service. So I need to create a double relationship for this field one with Article table an one with Service table.
Is this possible ?
If not , or if I'm wrong how can I solve this situation ?
Thank you.
This is kind of discussed in this thread , but the basic gist is that a foreign key can only be used to express a link and dependency between only two tables.
From pure SQL you might be able to write a trigger that could do some of these checks. This would require that you still need to make checks on the data during inserts updates and deletes to ensure consistency.
If you the data is being consumed by another application that supports the concept (such as hibernate) you could a discriminator or table per class hierarchy which provides certain frameworks with the ability to programmaticaly make the determination on the type of data and where to load it from, but this will not provide you with the constraints at the DB level that you are looking for.
Hope this helps a bit.
I know getting the id of a record from a db table in CakePHP is easy. I want to get the "future" id of a "future" record of a table, that is, I'll insert a record, but before inserting, I want to get its id, which will be generated by db after insertion is completed(the id is int, Auto Increment). Thanks.
Even the database itself doesn't know what ID it's going to use until the very moment after the record is saved.
You can't (in a multi-user system) ask in advance what the ID is going to be because 20 other records may have been inserted between the time you ask what the ID is going to be, and when you insert your record (with an ID that was used 20 records ago.) This is called a 'Race Condition'.
Here's what will happen:
You: DB - what's the next ID please?
DB: (Does a max() on the column) 21!
You: Great! I'll use that!
(meanwhile 20 other records get inserted by other users)
You: Hi DB, I'd like to insert this record using ID 21 like you told me!
DB: Oops - sorry - that ID has already been used :'-(
You don't NEED to know the record in advance. If you structure your save data correctly, and use CakePHP's saveAccociated() method, CakePHP will insert the correct ID as the foreign key value for all your related data.
The only way to have a predictable ID is to create it yourself. Remember - it MUST be non-null and unique (the definition of a primary key).
Save yourself many, many future primary key clashes and stick to the cake method :-)
One option is you can get the current max id from mysql and then just increment the value. If you have alot of operations going on this might cause some trouble with your site. But you could use:
$this->Model->query("SELECT MAX(id) as max FROM `your_table_name`");
This would get you the max id of that table currently then you can do a +1
Another option would be to get the ID after you save, then update your record with that ID. For example cakephp has a method for this.
$this->Model->getLastInsertID();
$this->Model->updateAll($fields, $conditions)
Reference updateAll: http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-updateall-array-fields-array-conditions
I'm writing my first database application and I've got an ambiguity I can't seem to find an answer for. I have an id field that is the identity set to auto-increment. My issue is trying to determine when the field is incremented. Is the field incremented when I call an instance of the object, when I call the AddObject method of the ObjectContext class, or when I call the SaveChanges method from an Entity model.
In my relational database each table has both a unique ID for that table and one that represents a group of users. After I create an instance of an object for that table I want to run a query (LINQ) that searches two tables to match two records and from one of those tables copy that group ID back to the individual user.
That or it is blatently obvious I know nothing about how relational databases work,
The identity field is handled by the database. It is created by the database when the row is inserted. The generated id is read back by SaveChanges and the entity object is updated.
WHen you add a new row to the database the counter is incremented.
If you have an ambiguity, this usually means that two tables fields are the same name, and your query doesn't know which one you want. Can be solved by defning which table the column is ment for.
I don't know LINQ, so hopefully someone can give you a more direct answer.