Automatic Primary Key Value Generation

Hi Everyone,

I am new to VP and am trying to figure out exactly how I go about creating a unique value for a primary key. The user’s guide that comes with VP mentions the ID generator property in the column definition screen, but is vague. Does the VP generated code actually generate a unique identifier value? If so, what are the correct settings? This is my guess as to how it is done, if in fact VP supports this feature:

Column properties:

name: personID
type: int
ID Generator: native
Generated: always
included in primary key: yes
unique: yes

Also, we are using SQL Server, which has the ability to perform the same service using the Identity column property (set to true) and using the function NEWID() as the default value. My question is, using the column properties in VP, how can I implement this? My guess is that the following properties must be set:

name: personID
type: int
Default Value: NEWID()
ID Generator: insert
include in primary key: true
unique: true

Can someone shed some light of this poorly documented feature? Has anyone used SQL Server and VP in this manner? Has anyone used VP for this purpose? Is there more documentation on the subject?

Thank You -

Ricky Miller
Edison Chouest Offshore

Hi rmiller511,

Thank you for the post. Let me reply your questions one by one.

To create a unique PK that will be generated automatically, you need to set “native” as the ID Generator of the PK column. Of course, you need to include that column in primary key. Please read the attached image as reference.

Sorry but I am not very familiar with NEWID() for SQL Server, but I just performed some checking, it looks like NEWID() is for producing a unique string value, something like “B1C1BEE4-E33A-4B4A-BB80-418A8341656A”, right? If you want to create a unique PK in varchar, you need to set ID Generator as guid. Since you mentioned “implement”, I believed that you also want to know how to work with the coding part. Actually, you don’t need to care about the ID column when coding as it will be taken care by ORM internally. Just in case you are unclear about how to use the generated code, I’ve captured a movie to show you in detail. Please watch by visiting:
http://files4.visual-paradigm.com/200904/unique-string-pk/unique-string-pk.htm

The movie was demonstrated using SDE for Eclipse. You can do the same in other products that support ERD and ORM, like DB-VA and VP-UML!

Hope this helps. Please feel free to post again for any questions.

Best regards,
Jick

native-id-generator.png

Hi Jick,

That you so much for the speedy response. You pretty confirmed my suspicion in as much as VP has the ability to generate the primary key values automatically for me. We are still in design mode so I have not been able to actually test that feature but it is enough just to know that it does.

In regards to SQL Server you are correct - NEWID() would be specified in the ‘default value’ field and generates values like the one you used as an example, which, for our applications, is not suitable.

Again, thank you so much for the help and the fast response.

Best Regards,

Ricky Miller
Edison Chouest Offshore

Hello Ricky,

You are welcome! and yes, VP has the ability to generate PK values automatically. My previous reply shows you the way to generate numeric and text IDs. I would also like to share with you that you can implement a custom ID generator yourself. If you need I can provide you with more information. :slight_smile:

Best regards,
Jick

[quote=Jick]Hello Ricky,

You are welcome! and yes, VP has the ability to generate PK values automatically. My previous reply shows you the way to generate numeric and text IDs. I would also like to share with you that you can implement a custom ID generator yourself. If you need I can provide you with more information. :slight_smile:

Best regards,
Jick[/quote]

Good Morning Jink,

At the moment i believe that VP’s standard method of PK generation will probably work fine for us but if that turns out not to be the case, i will get you to show me the customized method - but for now, I think we are OK.

Thank you,

Ricky Miller
Edison Chouest Offhore

Hello Ricky,

Good to know about this. Feel free to post again if you have any questions: :smiley: :smiley:

Jick