How to Set automatic growth of MySQL primary keys in powerdesigner

Source: Internet
Author: User
Tags powerdesigner

I have been using Oracle databases all the time, so when designing CDM, the primary keys of tables not selected will automatically grow. This is only available in SQL Server and MYSQL. In Oracle, SEQUENCE is generally used to handle the problem of primary key growth. Compared with writing programs, Oracle processing is more complex.

Open PDM, select a table, double-click to Open Table properties, select Columns, select the primary key field, and double-click to open it. At the bottom right corner of the interface, there is an Identity, the generated table primary key is automatically increased.

Manually modify a table. When will this happen!

I searched on google and found that many people encountered this problem, and another vbs script was executed once. You can search for the script named SetIdentity. vbs.

The script execution method in PD is also very simple. Tools -- Excecute Commands -- Edit/Run Scripts.

Another script is used to set the field name to the name2comment. vbs code of the comments field of the database field. It is also very useful. (Generally, the name is a Chinese description, and the code is the code)

SetIdentity. vbs

''''************************************ **************************************** *
''' File: SetIdentity. vbs
''' Version: 1.0
''' Copyright: floodzhu (floodzhu@hotmail.com), 2004.12.31
'''' Function: traverses all tables in the physical model and sets the field that is a primary key but not a foreign key as Identity, which is applicable
''' The physical model is of the MS SQL Server type.
'''' Usage: Open the physical model and run the script (Ctrl + Shift + X)
'''' Note: I have two habits: one is to define the primary keys of all tables as auto-increment int type, and the other is to define
'''' A Domain is called ID. When designing a conceptual model, set the Domain of all PrimaryKey fields to ID.
''' Type.
''''
'''' If I have configured the preceding settings, You need to manually set the Identity when converting to a physical model,
'''' The most stupid way is to set a table in a table. The simplest way is to directly set the Domain in the physical model.
. Setting Domain has a small disadvantage, that is, if this field is not a primary key or is not generated
'''' As a foreign key, but a general field, such as a tree structure PID, it will also be set
'''' Identity, but this field is relatively small, and an error occurs when the database is generated.
'''' It is a good method for you to correct the errors, so you can easily pass the customs without hiding the errors.
''''
''' You can use the following code to make a third choice without any errors.
''''************************************ **************************************** * Dim model ''' current model
Set model = ActiveModel

If (model Is Nothing) Then
MsgBox "There is no current Model"
ElseIf Not model. IsKindOf (PdPDM. cls_Model) Then
MsgBox "The current model is not an Physical Data model ."
Else
ProcessTables model
End If

''''************************************ **************************************** *
'''' Function: ProcessTables
'''' Function: recursively traverse all tables
''''************************************ **************************************** *
Sub ProcessTables (folder)
''' Process Tables in the Model
Dim table
For each table in folder. tables
If not table. isw.cut then
ProcessTable table
End if
Next

''' Recursion of sub-Directories
Dim subFolder
For each subFolder in folder. Packages
ProcessTables subFolder
Next
End sub

''''************************************ **************************************** *
'''' Function: ProcessTable
'''' Function: traverses all fields in the specified table. If this field is a primary key but not a foreign key, it is set to Identity.
''''************************************ **************************************** *
Sub ProcessTable (table)
Dim col
For each col in table. Columns
'''': Set the primary key fields that are not foreign keys to Identity (auto-increment type)
If col. Primary and not col. ForeignKey then
Col. Identity = true
End if
Next
End sub

Name2comment. vbs

'*************************************** ***************************************
'* File: name2comment. vbs
'* Purpose: Database generation cannot use object names anymore
'In version 7 and above.
'It always uses the object codes.
'
'In case the object codes are not aligned with your
'Object names in your model, this script will copy
'The object Name onto the object Comment
'The Tables and Columns.
'
'* Title:
'* Version: 1.0
'* Company: Sybase Inc.
'*************************************** ***************************************

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

Dim mdl 'the current model

'Get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model"
Elseif not MDL. iskindof (pdpdm. cls_model) then
Msgbox "the current model is not an physical data model ."
Else
Processfolder MDL
End if

'This routine copy name into comment for each table, each column and each view
'Of the current folder
Private sub processfolder (folder)
Dim tab 'running table
For each tab in folder. Tables
If not tab. isw.cut then
Tab. Comment = tab. Name
Dim Col 'running Column
For each Col in tab. Columns
Col. comment = col. name
Next
End if
Next

Dim view 'running view
For each view in folder. Views
If not view. isw.cut then
View. Comment = view. Name
End if
Next

'Go into the sub-packages
Dim f'running folder
For each F in folder. Packages
If not F. isw.cut then
Processfolder F
End if
Next
End sub

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.