can 2 field in 1 table set as primary key using sql? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

can 2 field in 1 table set as primary key using sql?

I'm using MS Access to create a database, my lecturer require us to create two primary keys in one of the table. Using Access itself i definitely cant do that, but by using SQL coding/statement, can i create 2 primary key in one table?

i'm using VB6 as the programming language. If anyone of you know anything about my question, please kindly reply to my forum as soon as possible...thanks!

Comments

  • infidelinfidel Posts: 2,900Member
    : I'm using MS Access to create a database, my lecturer require us to create two primary keys in one of the table. Using Access itself i definitely cant do that, but by using SQL coding/statement, can i create 2 primary key in one table?
    :
    : i'm using VB6 as the programming language. If anyone of you know anything about my question, please kindly reply to my forum as soon as possible...thanks!

    The definition of "primary key" means there can be only one. You can, however, add additional unique keys to other fields (in most databases, don't know about Access) or make the primary key composed of multiple fields (which is probably what you need).

    alter table tablename add constraint constraintname primary key (field1,field2);


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

  • JonathanJonathan Posts: 2,914Member
    : I'm using MS Access to create a database, my lecturer require us to create two primary keys in one of the table. Using Access itself i definitely cant do that, but by using SQL coding/statement, can i create 2 primary key in one table?
    :
    : i'm using VB6 as the programming language. If anyone of you know anything about my question, please kindly reply to my forum as soon as possible...thanks!
    :

    Yes, you can do it and it can be useful to do it sometimes, when you have two values that are unique as a pair, but you would prefer to be able to access seperately at times.

    Don't know MS Access's SQL Create Table syntax (the M$ interpretation of a standard is, as normal, a little...uh...off :-)). However, you can do it in MS ACCESS if you highlight the two rows in the table design view, right click and choose primary key from the menu. You have to right click in the right place though (on the line seperating the two selected fields seems to work) otherwise it just re-highlights the one and sets the primary key just on that! Argh!

    The official term for a primary key made up of 2 or more fields is a composite primary key.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.