PowerDesigner script: Automatically set up the code of the Identity property

xiaoxiao2021-03-06  50

'********************************************************** ************************************* 'file: setIdentity.vbs' version: 1.0' copyright: floodzhu (floodzhu@hotmail.com), 2004.12.31 'Features: Traverse all tables in the physical model, set the primary key but the field of the foreign key is set to Identity, which is suitable for the' physical model as the type of MS SQL Server. 'Usage: Open the physical model, run this script (Ctrl Shift X)' Note: I have two habits, one is to define all the primary keys of all tables as the intimate Int type, the other is definition 'a Domain called ID, set the Domain of all PrimaryKey fields to ID 'when designing a concept model. '' If I have the above setting, you need to manually set the Identity when converted to a physical model, 'The most stupid method is a table for setting, the simplest method is to set Domain' directly in the physical model. . Setting a small disadvantage for Domain, that is, if the field is not a primary key, it is not a foreign key, but a general field, such as a PID of a tree structure, it will also be set to 'Identity, but due to This field is relatively small, and an error can occur when generating a database, you can remind 'you correct, so you can easily pass without hiding errors, so it is a good way. '' Use the following code to give you 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 'Features: Recursive Traversal All Table' ********* *********************************************************** ******************

Sub

Processtables (Folder)

'Treatment in the model

DIM TABLE

For Each Table in Folder.tables

IF not Table.isshortcut then

Processtable Table

END IF

NEXT

'Recurrence of subdirectory

DIM Subfolder

For Each Subfolder in Folder.Packages

Processtables SubfolderNext

End Sub

'********************************************************** ************************************* Function: Processtable 'Features: Traversing all fields of the specified table, if the field is the primary button but not outside Key, set to Identity '*************************************************** ****************************************

Sub

Processtable (TABLE)

DIM COL

For Each COL in Table.columns

'Set to Identity for the primary key and not the foreign key (self-growth type)

IF col.primary and not coloreignkey then

Col.Identity = TRUE

END IF

NEXT

End Sub

转载请注明原文地址:https://www.9cbs.com/read-74289.html

New Post(0)