Some of the assets are not present in alm_hardware table which are present in cmdb_ci - assets

I am working on ITSM, Some of the assets which are present in the cmdb_ci table are not in the alm_hardware table. Kindly help me to get those assets in the alm_hardware table.
Assets that are present in cmdb_ci table, should be reflected in alm_hardware table

Related

Avoid duplicate insert into SQL table

I have built a SQL table with over 20 attributes and 20M lines. Just recently the data owner told me that some data was missing from the original supply! The new txt files provided now contains both existing and newly added data.
I am wondering how can I insert only the added data from txt files to the table and avoid the duplicate records already in there? I will need to make all 20 attributes as the key for the duplication check, can I do that?
Thanks in advance.

How to remove Duplicates and update all relations from PostgreSQL database?

I'm working on updating a local dataset that has a lot of cases with the following structure:
The elements in table A that share the same refID for the main entity are virtually the same, so I wanna remove all these duplicates and update tables B, C and so on.
The idea is to group all elements in table A that share the same refId, choose one, remove all the others and change the references in other tables to the one I chose. However, I'm having problems with the last part, updating the other tables.
Is there a quick way of doing this? Doing it manually has been a pain

Postgresql question for changing data without effecting table

Tables
The above image shows the table that I have created in postgresql.
Say if I create an account saying 'entertainment' and add 40 entries to it over a month
before realizing that I spelt it as entertainmunt.
so now, you'd want to rename that account, right?
With this table structure..
how should achieve that?

Is it possible to have a generated column based on another table?

I was wonder if it was possible to create a generated column by using a group by query. For example, in the diagram below, is it possible to have the quantity of a equipment be generated based on the number of asset that matches it's foreign key?
You can't do that with a computed column. If you wanted to store and maintain such information, you would need trigger code for every DML operation on table asset , which makes things rather complex.
You can, on the other hand, create a view:
create view v_equipment
select e.*,
(select count(*) from asset a where a.equipment_id = e.equipment_id) as quantity
from equipment e
This gives you an always up-to-date perspective at your data. You can query the view directly instead of the table whenever you need the quantity information.

History of a grouped query

I have a problem and I think someone can help me here.
I have a sales table, with a reference to the product,the saleId and the price. At the moment I have a query, which does a group by product and send the grouped data back to the application. But now I would love to have a log, which entries I have grouped in this query. The problem is, that only the grouped entries are saved in another Stored Procedure, if the users saves it in the application.
My suggestion for this problem:
Before I do my group by query. I would save all entries in a new table with e temporary Id. Then I would send the temporary id with the data back to the application and if the users saves it, the temporary id would be saved in n:m table with the real ID.
What are your suggestions about this problem?