lkarthikraj-609584 (1/12/2009)
Cannot find index 'PK__EventStage__46AF6B36'
That's the problem with relying on system-generated names for constraints, such as primary keys.
You would think Microsoft would know better.
USE tempdb;
GO
CREATE TABLE #SystemGenerated
(
-- No constraint name specified
row_id INTEGER IDENTITY NOT NULL PRIMARY KEY
);
GO
CREATE TABLE #Explicit
(
row_id INTEGER IDENTITY NOT NULL,
-- Explicitly named constraint
CONSTRAINT [PK #Explicit row_id]
PRIMARY KEY CLUSTERED (row_id ASC)
WITH (FILLFACTOR = 100)
ON [PRIMARY]
);
GO
-- Show primary key details
SELECT constraint_name = name,
type_desc,
is_system_named,
table_schema = SCHEMA_NAME([schema_id]),
table_name = OBJECT_NAME(parent_object_id)
FROM sys.key_constraints
WHERE parent_object_id = OBJECT_ID(N'tempdb..#SystemGenerated', N'U')
OR parent_object_id = OBJECT_ID(N'tempdb..#Explicit', N'U');
GO
-- Clean up
DROP TABLE
#SystemGenerated,
#Explicit;
Paul
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi