2 primary Keys in 1 table

How do I create 2 primary keys in 1 table in vb05ee. I know this can be done because I am looking at a table sample with 2 primary keys in it.

Help

[160 byte] By [ykgreene] at [2007-12-22]
# 1
Thread moved to VB.NET Express forums.
ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

You can't create two primary keys in a table in SQL. Are you sure its 2 primary keys or is it two fields which make up a primary key.

You could create a primary key and a unique key or two unique keys - but by definition there is only one Primary Key.

Also VB 2005 Express edition is a development environment which supports two database - Access and SQL Express. The same applies to both database but to provide more specific details - you need to provide more information about which you are using.

spotty at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

In the designer select the columns that you want to set as Primary Keys and then right click and select

"Set Primary Key"...this action will set all selected columns to the Primary Key

DMan1 at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 4
If I remember correctly, if you select more than 1 column to make it a "primary" key, its known as a composite key - a key which is combined of more than 1 column, so really its not a primary key but a composite key and as spotty said, there will only ever be 1 primary key in a table
ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 5

You and spotty are technically correct about the composite key....However the answer to the question is as stated above...The designer uses the terminology "primary key" no matter how many columns you are setting at the time...

SO there maybe 1 primary key but mulitple columns can make up a primary key...and inorder to do that follow the given instructions!!!

DMan1 at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 6

The user asked about setting up two primary "keys"

The operative part here is the plural keys - a table cannot have two primary keys.

The designer allows you to select as many fields as you want to create a (singular) primary "Key"

This field can be a single field key or a composite key field but there still can only ever be one primary key.

spotty at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 7
DMan1 wrote:

spotty wrote:

The designer allows you to select as many fields as you want to create a (singular) primary "Key"

Please take note of my response when I said "THE" primary key....

DMan wrote:

"...this action will set all selected columns to the Primary Key

I'm sure all of this verbose conversation is to help clarify this for all of the noobs who don't know any better


It depends on your defintion of 'is'....

SJWhiteley at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 8

I was simply referring the the title of the thread

"2 primary keys in 1 table"

You cannot have two primary keys in 1 table. You can only have one primary key in a table.

spotty at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...