How can I change primary key of table???

GRUBBYFANSGRUBBYFANS Member Posts: 154
How can I change primary key of table??? Please tell me and give me an Example :-k :-k

Comments

  • rajpatelbcarajpatelbca Member Posts: 178
    if you want to change primary key of inbuilt table then i will suggest that don't do that [-X otherwise it will create so many problems.

    object designer (sift +f12). open your table in table designer by clicking design button then go to view menu -> keys.

    you will have list of keys. first row is a primary key of that table. other are secondary keys.

    regards,
    Experience Makes Man Perfect....
    Rajesh Patel
  • DaveTDaveT Member Posts: 1,039
    Hi GRUBBYFANS,

    On the other hand if you are asking how to change the data record of a primary key then use the rename function

    e.g.
    IF Customer.GET( '10000' ) THEN
      BEGIN
       Customer.RENAME( 'new10000' );
    

    Note the rename function changes the position in the file and you must send all the parts of the primary key.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • arindomarindom Member Posts: 52
    If you want to change primary key valuea of a table through then


    "IF Customer.GET( '10000' ) THEN
    BEGIN
    Customer.RENAME( 'new10000' );"

    Right option .

    If u want to change field (which is primary key of the table ) then think the side effects .
  • GRUBBYFANSGRUBBYFANS Member Posts: 154
    Thanks a lot !! I know How figure out problem
  • GRUBBYFANSGRUBBYFANS Member Posts: 154
    This is My code ,hehe It is too long
    Code:
    "GRED_Sales Price".SETRANGE("Starting Date",080601D);
    IF "GRED_Sales Price".FIND('-') THEN
    REPEAT
    IF "GRED_Sales Price".GET("GRED_Sales Price"."Item No.","GRED_Sales Price"."Sales Type","GRED_Sales Price"."Sales Code"
    ,"GRED_Sales Price"."Starting Date","GRED_Sales Price"."Currency Code","GRED_Sales Price"."Variant Code",
    "GRED_Sales Price"."Unit of Measure Code","GRED_Sales Price"."Minimum Quantity") THEN
    "GRED_Sales Price".RENAME("GRED_Sales Price"."Item No.",2,"GRED_Sales Price"."Sales Code",
    "GRED_Sales Price"."Starting Date",'',"GRED_Sales Price"."Variant Code",'pc',"GRED_Sales Price"."Minimum Quantity");


    UNTIL "GRED_Sales Price".NEXT=0;

    Code
  • DaveTDaveT Member Posts: 1,039
    Hi GRUBBYFANS,


    Two observations of your code
    1. why the get your already have the record with the find
    2. You are using the same record variable in the rename which will reposition the record for the next.

    The get should be to see if the new key exists i.e. UOM 'pc' and rename if not found.
    Also use two new record variables to avoid repositioning
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • GRUBBYFANSGRUBBYFANS Member Posts: 154
    DaveT wrote:
    Hi GRUBBYFANS,


    Two observations of your code
    1. why the get your already have the record with the find
    2. You are using the same record variable in the rename which will reposition the record for the next.

    The get should be to see if the new key exists i.e. UOM 'pc' and rename if not found.
    Also use two new record variables to avoid repositioning

    Thank you DaveT!! I found my code where is bug,you are very good!!
  • DaveTDaveT Member Posts: 1,039
    Glad to help :mrgreen:
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
Sign In or Register to comment.