Skip to content

FillSchema() reports CLUSTERED alternate key as primary key if the primary key is declared as NONCLUSTERED #3824

@srana1-equitable

Description

@srana1-equitable

I have this table definition:

CREATE TABLE [dbo].[TEST](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[ENTITYID] [int] NOT NULL,
	[LEVELNO] [smallint] NOT NULL,
	[STATUS] [smallint] NOT NULL
 CONSTRAINT [PK_TEST] PRIMARY KEY NONCLUSTERED  ([ID] ASC) ON [PRIMARY],
 CONSTRAINT [AK_TEST] UNIQUE CLUSTERED ([ENTITYID] ASC,	[LEVELNO] ASC) ON [PRIMARY]
) ON [PRIMARY]

and this C# code:

        var dt = new DataTable();
        using (var da = new SqlDataAdapter(cmd))
        {
            // This populates dt.Columns and dt.PrimaryKey
            da.FillSchema(dt, SchemaType.Source);
        }

        Console.WriteLine("Primary key columns:");
        foreach (var col in dt.PrimaryKey)
        {
            Console.WriteLine(col.ColumnName);
        }

It shows ENTITYID and LEVELNO as part of primary key, instead of ID.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions