Compare staging table records and target table records and reflect the missed out record in a column in staging table itself in servicenow? - scripting

I have a staging table called u_xyzand a target table called sn_abc.
The target table contains other records too from different staging table. 
I need to compare whether all the records from staging table(u_abc) is getting reflected in target table(sn_abc) and the records  which are missing out in the target table needs to be highlighted in a column(missedout records) in staging table?
Please tell me how to pass 250+ import sets in the below code ? 

Related

Teradata - Which approach is faster for larger tables, update or delete and insert

I have a very large table in Teradata.
I have to run a UDF on a column and store the output of the UDF back in to the column.
We can do it in two ways
do a direct update of that column using the update query
create a staging table and select the rows with UDF applied and load the staging table. then delete all the rows from the original table and load the data back from the staging table.
Which is a better option performance-wise?

Append data from one table to another table

I have a Destination table with 3 columns, ID, Name, Source.
I have 10+ Source tables, each with multiple columns, but I only require the ID, Name, and the table name itself to be appended into Destination table.
Do note the naming of the column names are different in each table, but the required ID and Name are of the same data type and are of sufficient length for the ID and Name fields.
I already have the query to add the data (see below), and I have no issues doing the first run to add the required data into the destination table, as I just need one query for each table, Here is one my code below
INSERT INTO dest_table
SELECT ID, Name, 'source_table' as Source
FROM source_table
The issue now is that I need to schedule this to run on a daily basis.
I would like the source tables to append their new data into the destination table, and not add all records from each source table into the destination table.
Another condition to consider is that I will still need the data from the destination table to be intact. This means what ever records that were removed from the source tables , will not be removed from the destination table.
Thanks people!
You can exclude the old data by using a WHERE clause as shown below. I am assuming that the ID is unique in this table among all tables else you need to add another column in the destination table to identify where this ID is coming from
INSERT INTO dest_table
SELECT ID, Name, 'source_table' as Source FROM source_table
WHERE NOT EXISTS (SELECT 1 FROM dest_table dt WHERE dt.id = source_table.id)
Another non-optimal approach would be to create a trigger on insert in the source tables and push the data to the destination table.

update 100 million records in a table?

I have source and target table containing 100 columns and 100 million of records each. Now my source table got updated with extra 5 columns i.e. now my source table is having 105 columns and 100 millions of records.
I want to update my target table with the extra 5 columns and update the data as well added in the source table.how can i do it with the best optimized approach ?(may be something like update and insert)
The source and target table is having one to one mapping of columns. there is no transformation happening from source to target table.The source table is truncate load so there might be case of new records added or some records present in target but not in source.
enter image description here

How to replicate records using PLSQL in two tables

I have two existing tables and many records already added.
formula(formulaId,formulaName,formulaType)
and formula_detail(detailId,formulaId,fieldType,value)
Now there is change in formula table and new column is being added , branchId as
formula(formulaId,formulaName,formulaType,branchId),
and branch table is branch(branchId,branchName)
I want to copy and paste every existing record in formula table for every branch.
e.g if there are 3 existing records in formula table (with ID 1,2,3) and 2 branches. Then copy paste operation should produce total new (3*2)=6 records in formula table and also replicate records in formula_detail table for every newly created formula as follows
for formulaId 1 , If there were 5 records in formula_detail table, then copy paste in formual_detail table will have (2*5) new records added in formual_detail table.
I tried some solutions but number of are records huge and script is taking time. Please help. If need any test code I can add.
First of all replicating same column in detail table is against the Normalized Form used in your Data model.
Still If you want to add the column anyway,
Add the column using ALTER statement in formula_detail table
Try using this Merge statement
.
MERGE INTO formula_detail fd
USING (SELECT formulaId, branchId from Formula) temp
ON (fd.formulaId=temp.formulaId)
WHEN MATCHED THEN
UPDATE SET fd.branchId=temp.branchId;

Want to synchronize two table in oracle without using DBMS_COMPARISON

I have two identical tables in the database (Same column name, same data type). Table A and Table B.
A is the master table. Now i want to update the table B with the changes done in the master table A automatically at any point of time. How would i do that without using DBMS_COMPARISON