Reputation: 666
When I try run a simple create table script I get the "there is already an object..." error. Then when I run the select:
SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[tableX]')
There are no rows returned.
Here is what my create script looks like:
USE [DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tableX](
[id] [int] IDENTITY(1,1) NOT NULL,
[colA] [int] NOT NULL,
[colB] [nvarchar](500) NOT NULL,
[colC] [nvarchar](500) NOT NULL,
[colD] [nvarchar](max) NOT NULL,
[colE] [int] NOT NULL,
CONSTRAINT [tableX] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
Upvotes: 1
Views: 2650
Reputation: 70678
Well, it seems that you are trying to create a CONSTRAINT
with the exact same name as your table.
CONSTRAINT [tableX] PRIMARY KEY CLUSTERED
Change it for something like:
CONSTRAINT [pk_tableX] PRIMARY KEY CLUSTERED
Upvotes: 7