title: SQL Server : IF EXIST update or insert between similar database tables
body: <p>I would like to use a simple code to update or insert a record beetween two similar databases.</p>
  
  <p>In <strong>A</strong> database there is a table like this:</p>
  
  <pre><code>CREATE TABLE [dbo].A.[tblDuyurular]
  (
          [ID] [int] IDENTITY(1,1) NOT NULL,
          [SiteID] [int] NOT NULL,
          [Dil] [varchar](7) NULL,
          [DuyuruBaslik] [varchar](250) NOT NULL,
          [DuyuruIcerik] [varchar](max) NOT NULL
  )
  </code></pre>
  
  <p>In <strong>B</strong> database:</p>
  
  <pre><code>CREATE TABLE [dbo].B.[TBLDuyurular]
  (
      [ID] [int] IDENTITY(1,1) NOT NULL,
      [fakulteID] [int] NOT NULL,
      [DuyuruBaslik] [varchar](250) NOT NULL,
      [DuyuruIcerik] [varchar](max) NOT NULL,
      [dil] [varchar](7) NULL
  )
  </code></pre>
  
  <p>Matched columns are:</p>
  
  <pre><code>ID = ID,
  SiteID = fakulteID,
  Dil = dil,
  DuyuruBaslik = DuyuruBaslik,
  DuyuruIcerik = DuyuruIcerik,
  </code></pre>
  
  <p>I want to check dbo.B.TBLDuyurular records. If records exist in dbo.A.tblDuyurular then UPDATE dbo.A.tblDuyurular with dbo.B.TBLDuyurular's results. If records not exist in dbo.A.tblDuyurular, INSERT dbo.B.TBLDuyurular's results to dbo.A.tblDuyurular. Table columns are minimized. There are too many columns in these tables.</p>
  
  <p>What is the best way for this situation?</p>
  
  <p>Help please. Thanks.</p>