Change primary key
krithika
Member Posts: 56
How to change primary key for a set of records without deleting the records and without using temp table ](*,)
0
Comments
-
Where do you need?
Did you try with RENAME?0 -
Loop though the records and use the RENAME function to rename the individual records.
Regards0 -
Thanks for the response. I have a table which has three fields as primary key. In that i am trying to modify a field which is of integer data type. When i loop it and modify the first record it goes and saves in the table as last record hence the loop terminates abruptly. Can u give me a solution for this?0
-
Temporarily you can create a field like PKChanged and Set it immediatly after changing and Put filter on PMChanged False..0
-
Is there any other options apart from the above provided scenario/solution0
-
Why don't you use above solution even it's simple?
if you are not able to add a field then you can use any other field that is not being used in your table.0 -
yes u can use like
rec.setrang(fields);
re. findfirst then
repeat
rec1.get(rec);
rec1.renbame(fields);
unitl rec.next=0
like aboveNav & LS Retail Technical Consultant
Ajageavi Nath Keshari0 -
Hi
To get this to work you need to use another sorting key than the Primary Key. It is also good practice to use another variable to do the changes in.
E.g. like thisMyVar.SETCURRENTKEY(NotPK); REPEAT MyVar2 := MyVar; MyVar2.RENAME(Value1 [, Value2] ,...); UNTIL MyVar.next = 0;
Regards0 -
Thanks for ur replies,i have changed the primary key,but the system provides default message As do u want to change the primary key. Yes/No.. for each record Rather than providing YES for each key can i be able change as YES by default for only once which changes entire set of PK to be changed.
Any soultions ..0 -
May I know how are you doing?0
-
NEVER use FINDFIRST in a loop! you need to use the FINDSET-statement. But the idea is correct. The correct code to rename is this:ajageavi wrote:yes u can use like
rec.setrang(fields);
re. findfirst then
repeat
rec1.get(rec);
rec1.renbame(fields);
unitl rec.next=0
like aboverec.RESET; rec.SETCURRENTKEY(...); rec.SETRANGE(...); IF rec.FINDSET(TRUE,TRUE) THEN // check the help for info on the parameters of FINDSET REPEAT rec2 := rec; rec2.RENAME(new key fields); UNTIL rec.NEXT = 0;Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 328 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
