title: The operation failed because an index or statistics with name 'X' already exists on table 'Y'
body: <p>I am new to SQL and I have a SQL file and when I execute it the following error occurs:</p>
  
  <blockquote>
    <p>Msg 1913, Level 16, State 1, Line 463<br>
    The operation failed because an index or statistics with name 'DDT_PK' already exists on table 'DAILY_DATA_TYPE'.</p>
  </blockquote>
  
  <p>The error occurs when running this statement:</p>
  
  <pre><code>CREATE UNIQUE NONCLUSTERED INDEX DDT_PK 
      ON [DATE_DATA_TYPE]([TYPE_ID])
  GO
  
  ALTER TABLE [DATE_DATA_TYPE] 
      ADD CONSTRAINT [DDT_PK] PRIMARY KEY ([TYPE_ID])
  GO
  </code></pre>
  
  <p>I know that it already exists but I want to add a constraint and not create the index again so what am I doing wrong?</p>
  
  <p>Maybe u have to know how the table was created too so here is the statement:</p>
  
  <pre><code>CREATE TABLE [DATE_DATA_TYPE] ([TYPE_ID] [numeric](18, 0) NOT NULL,
  [TYPE_NAME] [varchar](400) NOT NULL, [UNIT] [varchar](32) NOT NULL,
  [CHART_TYPE] [varchar](32) NOT NULL, [RES_ID] [numeric](18, 0) NOT NULL)
  GO
  </code></pre>
  
  <p>I am using Microsoft SQL Server Management Studio.</p>