I am new to SQL and I have a SQL file and when I execute it the following error occurs:
Msg 1913, Level 16, State 1, Line 463
The operation failed because an index or statistics with name 'DDT_PK' already exists on table 'DAILY_DATA_TYPE'.
The error occurs when running this statement:
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
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?
Maybe u have to know how the table was created too so here is the statement:
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
I am using Microsoft SQL Server Management Studio.