title: T-SQL check if primary key exists in duplicated table
body: <p>I ran into a problem where I need to figure out if a primary key value already exists in my table.</p>
  
  <p>I transfer data from an ERP system into my SQL Server database, this data is split in many tables all have different clustered PK.</p>
  
  <p>To prevent dataloss, caused through locked data, I build a way that dublicates all tables and copies data from table a to table b in my SQL Server. </p>
  
  <p>To have better performance I only transfer x month back of data from the ERP and not always all data. Plus there could be changes in the new data that I need to track.</p>
  
  <p>My question is, is there a way, that I can dynamicaly copy only data, that is new and update data that got changed? </p>