In my current environment there are hundreds of DB tables with 20% master tables. The values of some of the columns is a subset of a column from the master table. Unfortunately it is not documented.
Wondering if the master tables and dependent tables are known, how to craft a SQL statement to get which column of the dependent table is a subset of the master table column.
Thanks,
cabear
Related
Once a day I have to synchronize table between two databases.
Source: Microsoft SQL Server
Destination: PostgreSQL
Table contains up to 30 million rows.
For the first time i will copy all table, but then for effectiveness my plan is to insert/update only changed rows.
In this way if I delete row from source database, it will not be deleted from the destination database.
The problem is that I don’t know which rows were deleted from the source database.
My dirty thoughts right now tend to use binary search - to compare the sum of the rows on each side and thus catch the deleted rows.
I’m at a dead end - please share your thoughts on this...
In SQL Server you can enable Change Tracking to track which rows are Inserted, Updated, or Deleted since the last time you synchronized the tables.
with TDS FDWs (Foreign Data Wrapper), map the source table with a temp table in pg, an use a join to find/exclude the rows that you need.
I have a source table in a Sybase database (ORDERS) and a Source table in an MSSQL Database (DOCUMENTS). I need to query the Sybase database and for each row found in the ORDERS table get the matching row(s) by order number from the DOCUMENTS table.
I originally wrote the SSIS package using a lookup transformation, simple, except that it could be a one-to-many relationship, where 1 order number will exist in the ORDERS table but more than 1 documents could exist in the DOCUMENTS table. The SSIS lookup will only match on first.
My 2nd attempt will be to stage the rows from the ORDERS table into a staging table in MSSQL and then loop through the rows in this table using a FOR EACH LOOP CONTAINER and get the matching rows from the DOCUMENTS table, inserting the DOCUMENTS rows into another staging table. After all rows from ORDERS have been processed I will write a query to join the two staging tables to give me my result. A concern with this method is that I will be opening and closing the DOCUMENTS database connection many times, which will not be very efficient (although there will probably be less than 200 records).
Or could you let me know of any other way of doing this?
SQL Server 2016 what are the advantages of using Horizontal Partitions.
I want to make multiple similar tables into 1 large table.
Ex : Progress_YearWeekNo is name of table which is created every week dynamicaly,i want to make it 1 common Progress table with YearWeekNo column on which i will be creating partition.
It will be huge data like 10M records in one table.
Below are my questions?
1.query to select from particular partition.
2.mark only 1 partition as ACTIVE and remaining as history.
As weekly new tables are created dynamically , there are more than 200 tables .So if i combine all tables and partition it will be more manageable table than having more tables of similar type.
I have two DBs with identical structures and tables, and they both contain some identical and some different data.
my task is to transport all the records from DB1 to DB2, but I do not have to delete all the data present in DB2 before, I must first check if in DB2 there are different records from DB1, not present in DB1. If there is a different record in DB2 it should not be deleted. The problem that starting from the insert extrapolated from the DB1, can have the same IDs to the DB2 and therefore the insert command will give the duplicate key error.
I'm carrying out a manual operation, very onerous in terms of time:
With excel, in a card insert the result of the select of a table of the DB1, and in another card the result of the same table but of the DB2.
Subsequently, with the vertical search, I verify the data that are more on DB2. If I find them, group them and change the id (seeing the max id of the DB1 table), then I check the weak or related tables connected to them and change the external id to the strong table to which I changed the id and also changing the id of weak and relational tables, as done previously. all this with "update table set id = 15000 where id = 101"
Finally, put the extra records in place, do a delete of the rest and execute the inserts taken from the DB1. (all right)
But done this for every strong table, which in turn has "n" weak and relational tables is a massacre. (if done on one or two tables ok, but since it is happening to me often I need something a little more automated)
Do you have any info to give me?
Thanks in advance
SQL Server Transactional Replication:
I understand that T-Rep supports both row and column filters and this can be done through the GUI while setting up replication.
I am trying to create SQL code which can list down all the filters (row and column) for all the tables which replicate from publisher. This must be possible by querying the publisher DB.
Any help will be highly appreciated
For row filters you can query sysarticles which contains a row for each article defined. This table is stored in the publication database and contains 2 columns, filter and filter_clause which can help you identify row filters.
For column filters you can query sysarticlecolumns which contains one row for each table column that is published and maps each column to its article. This table is stored in the publication database.