Options

How to Find First Primary Key From Table Id ?

Purvesh_MaisuriaPurvesh_Maisuria Member Posts: 71
Hello Experts,

I want the List of First Primary Key from Table Ids, I Have All Table Ids, But do not able to find First Primary Key of those table,
I used object table to find table ids. If Any one have idea, give me hint, may be that small hint focus on my problem. Thanks in Advance.

Thanks & Regards.
Purvesh Maisuria.

Answers

  • Options
    bekiobekio Member Posts: 204
    Use table Key, and where keys are Enabled, and than Clusterd = TRUE.

    You have there Table No.
  • Options
    Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Or create a variable of type RecordRef, and use KeyIndex to loop through the keys: http://lmsmfy.com/?q=keyindex
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • Options
    Purvesh_MaisuriaPurvesh_Maisuria Member Posts: 71
    Hello Luc Van Dyck,

    Thank U Very Much, I Have No Words, How Can I Say Thanks To U People.

    Just Want To Say That U People Are "The Great". =D>

    I Solve My Problem From Your Suggested Link. Hope U People Help & Support When We Are In Problem In Future.

    Thanks & Regards,
    Purvesh Maisuria.
  • Options
    BeliasBelias Member Posts: 2,998
    bekio wrote:
    Use table Key, and where keys are Enabled, and than Clusterd = TRUE.

    You have there Table No.
    this is not true: the clustered key is not always the primary key. (or at least, it is not guaranteed)
    Luc's method is the easiest one
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    Purvesh_MaisuriaPurvesh_Maisuria Member Posts: 71
    Hello Belias,

    May Be U R Right, But I Didn't use That, I Write Some Code To Get First Primary Key Of Table.

    ===================Variables=================
    Obj1 Record Object
    PK KeyRef
    RecRef RecordRef
    i Integer
    Field FieldRef
    KeyString Text 1024
    First Integer
    ===================Code====================
    Obj1.RESET;
    Obj1.SETRANGE(Type,1);
    Obj1.SETRANGE(Obj1.ID,TableId);
    IF Obj1.FIND('-') THEN
    REPEAT
    RecRef.OPEN(Obj1.ID);
    PK:=RecRef.KEYINDEX(1);

    FOR i := 1 TO PK.FIELDCOUNT DO BEGIN
    Field := PK.FIELDINDEX(i);

    IF First=1 THEN
    BEGIN
    KeyString:=Field.NAME;
    First:=First+1;
    END
    ELSE
    KeyString:=KeyString + ',' +Field.NAME;
    END;

    TableName1:=Obj1.Name;
    TableKey:=KeyString;
    RecRef.CLOSE();
    KeyString:='';
    UNTIL Obj1.NEXT=0;
    ===================Code====================

    Thanks & Regards,
    Purvesh Maisuria.
Sign In or Register to comment.