Find out primary key name

7 views
Skip to first unread message

Антон

unread,
Jun 17, 2010, 6:13:42 AM6/17/10
to migratordotnet-devel
I've created column like this:
new Column("Column1", System.Data.DbType.String,
ColumnProperty.PrimaryKey)

Now I need to remove primary key constraint from this column and
create primary key for another one.
The problem is that generated primary key has random name like this:
PK__TableName__6D0E29E15DCAEF64
And it changes from database to database.

How to find out the name of the primary key dynamically?
I'm using MS SQL.

Todd Ropog

unread,
Jun 17, 2010, 1:21:53 PM6/17/10
to migratordotnet-devel
I don't know if there's a way to determine the name of an existing
primary key, so I can't help you there.

However, in the future I recommend using the AddPrimayKey method
instead. It lets you specify a name for the primary key.

I think there may be a bug in the primary key creation doing it the
way you are. I seem to recall that if you specify a multi-column
primary key it actually chooses a predictable name (much like SQL
Server does), but for some reason a single-column key gets the random
name.
Reply all
Reply to author
Forward
0 new messages