HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

SQL Server 2017 - CU25 - sp_pkeys - Wrong order

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
ordercu25serversqlwrongsp_pkeys2017

Problem

After our customers have installed CU25 there is a problem with the stored procedure sp_pkeys.
It may now return the wrong order if a primary key has multiple columns.

It can be tracked down in the code itself.
This is the 2017 CU25 variant:

```
create procedure sys.sp_pkeys
(
@table_name sysname,
@table_owner sysname = null,
@table_qualifier sysname = null
)
as
declare @table_id int
-- quotename() returns up to 258 chars
declare @full_table_name nvarchar(517) -- 258 + 1 + 258

if @table_qualifier is not null
begin
if db_name() <> @table_qualifier
begin -- If qualifier doesn't match current database
raiserror (15250, -1,-1)
return
end
end

if @table_owner is null
begin -- If unqualified table name
select @full_table_name = quotename(@table_name)
end
else
begin -- Qualified table name
if @table_owner = ''
begin -- If empty owner name
select @full_table_name = quotename(@table_owner)
end
else
begin
select @full_table_name = quotename(@table_owner) + '.' + quotename(@table_name)
end
end

select @table_id = object_id(@full_table_name)

select
TABLE_QUALIFIER = convert(sysname,db_name()),
TABLE_OWNER = convert(sysname,schema_name(o.schema_id)),
TABLE_NAME = convert(sysname,o.name),
COLUMN_NAME = convert(sysname,c.name),
KEY_SEQ = (SELECT convert(smallint, index_column_id)
FROM sys.index_columns
WHERE object_id = @table_id AND index_id = i.index_id and column_id = c.column_id),
PK_NAME = convert(sysname,k.name)
from
sys.indexes i,
sys.all_columns c,
sys.all_objects o,
sys.key_constraints k
where
o.object_id = @table_id and
o.object_id = c.object_id and
o.object_id

Solution

Are there any alternatives than downgrading or waiting for a fix from Microsoft (workarounds)?

Nothing supported for a problem with a system procedure, no.

What would be the best way to contact Microsoft to receive a fix as quickly as possible?

Open a case with Microsoft Support.

I believe they refund the cost if the cause is confirmed to be a product defect.

This issue was resolved in SQL Server 2017 CU27 and SQL Server 2019 CU15.

Context

StackExchange Database Administrators Q#299605, answer score: 9

Revisions (0)

No revisions yet.