0

I have a table with a composite primary key of 3 values:

SELECT sifra_kapit_proj,
       sifra_aktivnosti,
       sifra_funkcije,
       naziv_aktivnosti,
       row_version,
       sifra_programa
  FROM EFIN00123..aktivnost

The 3 starting with sifra_ are the primary key. I need to equalize the content from this table and the same table in another database (any rows from table 2 that aren't in table 1 need to be inserted). Normally, I'm doing an insert into select along the primary key, but it won't work here.
How to go around doing that?

For clarification, how I normally go around equalizing tables. This does not work since both tables have the exact same sifra_aktivnosti (or any of the other two values), but have different total number of rows

insert into EFIN00123..aktivnost
select sifra_kapit_proj,sifra_aktivnosti, sifra_funkcije, naziv_aktivnosti,
row_version, sifra_programa
from EKUF00123..aktivnost where sifra_aktivnosti not in
( select sifra_aktivnosti from EFIN00123..aktivnost )```
  • 2
    *"but it won't work here."* Why won't an `INSERT` work? – Thom A Apr 04 '23 at 09:31
  • T-SQL is a SQL dialect that is used by multiple products including Sybase, SQL Server, and Azure Synapse. What is the (R)DBMS product you are using here? [Edit] your question to tag that product, and (if relevant) the version tag for the product as well. – Thom A Apr 04 '23 at 09:34
  • 1
    Sample data and expected results would help – Charlieface Apr 04 '23 at 11:30
  • updated my first post with an example code of how I normally go about doing things. This table is an outlier, as 99% of our tables have just normal primary keys, not composites. What I have to do it take the table with more data and insert the missing rows into the other table. I could perhaps create a view that is a copy of the table with a additional colum that is a concatenate of the 3 values, effectively creating a new primary key to search/compare trough and do inserts, which can then be deleted? – EternallyConfused Apr 05 '23 at 06:46
  • Please show sample data and expected results otherwise it's hard to understand – Charlieface Apr 05 '23 at 10:10

0 Answers0