Powerdesign Advanced Applications
Write the related VBS script to customize some commands and operations in Powerdesign, and refer to the script example in C:\Program files\sybase\powerdesigner 9\vb scripts directory. How do you use these scripts?
Operation can be performed in tools-"Execute commands. Specific instructions are clearly written in the help. The location of the help in PowerDesigner General Features guide-> Part 2. Modeling Guide->chapter 8. Managing objects->accessing Objects using Vbscript->vbscript uses in PowerDesigner
The use of Powerdesign is primarily the configuration of the DBMS
1. Modify the Build table script generation rules. If each table has the same field, you can modify it as follows:
Database---Edit current DBMS expand Script---Object---Table---Create the value below the right, which can be directly modified as follows:
/* TableName:%tname% */
CREATE TABLE [%qualifier%]%table% (
%tabldefn%
TS char (+) NULL default convert (char (+), GETDATE (), 20),
Dr smallint null default 0
)
[%options%]
The TS, Dr Two columns are automatically inserted into each table when the SQL script is generated, and the%tname% variable is a name value comment for each table that is added to the SQL table.
2. Modify the field generation rule. To add a comment to each field, expand the value of add in the same window with Column-----Object-----to:
%20:column% [%compute%?as (%compute%):%20:datatype% [%identity%?%i dentity%:[%null%][%notnull%]][default%default%]
[[Constraint%constname%] Check (%constraint%)]]/*%colnname%*/
Where%colnname% is the name value of the column (can be in Chinese)
3, modify the foreign key naming rules. Select Database->edit Current DBMS
Choose scripts-"objects-" reference-"Constname
You can see that the value on the right is:
fk_%. u8:child%_%. u9:refr%_%. u8:parent%
Visible, the naming method is: ' Fk_ ' + 8-bit child table name + 9-bit reference name + 8-bit parent table name, which you can customize according to this pattern:
fk_%. u7:child%_relations_%. u7:parent%,
The FK name can be changed to Fk_table_2_relations_table_1
After mastering this method, you can modify it according to your own ideas.
Creating a header comment in the SQL file of the build library script it is annoying to select the options card in the Databse-Generate Database (ctrl+g) window to remove the usage title Hook option.
4. Add foreign keys
Model-References Create a new foreign key, double-click into the foreign key property, in the "Joins" card can select the child table's foreign key field
5, remove the generated SQL script double quotation mark problem: ORACLE 8i2::script\sql\format\casesensitivityusingquote to No, the default is yes so there will be double quotes.
When you modify the name, the value of code is changed, which is inconvenient. Modification method: Powerdesign In the Options menu, in [Tool]-->[general options]->[dialog]->[operating modes]->[name to Code Mirroring], the default is to let the name and code synchronization, the previous check box is removed on the line.
1. Do not include a drop statement when generating code
In the menu Database->generate Database, select the Options tab in the Pop-up window, remove the window to the right of the drop ... option.
2. In the generated code, the field default value does not need to bring single quotation marks ', such as Default ' To_char (sysdate, ' yyyymmdd ') ' To change to default To_char (Sysdate, ' YYYYMMDD ')
In the menu Database->edit current DBMS ..., select the General tab, select Script->quote on the left side of the window, and then remove the single quotation mark behind the value on the right side of the window.
3. How do I remove the double quotes of an object in the generated build table script?
To open the CDM, enter Tools-model options-naming convention, set the Charcter case option for the label name and code to uppercase or lowercase, as long as it is not mixed Case on the line!
Or choose Database->edit Current Database->script->sql->format, there is a casesensitivityusingquote, it's comment for " Determines if the case sensitivity for identifiers is managed using double quotes ", indicating whether the quotation marks are applied to specify the casing of the identifier, you can see that the values on the right are the default values" YES ", instead of" No "!
Or, if you turn on PDM, go to Tools-model options-naming Convention, and set the charcter case option for the label name and code to uppercase!
4. Change the type of MySQL table, such as by default MyISAM to InnoDB
To modify a single table, in the Properties window of the table, select the Physcial Options tab, double-click the Type= (ISAM) on the left side of the window on the right side, and then select SQL in the lower right of the window and modify it to type= (InnoDB)
If the type of the modified database is InnoDB type, open the Properties window of the model, select the MySQL tab, and enter InnoDB in the edit box after database type. Then select menu Database->default Physical option, then in the pop-up window, double-click to select Type=[isam], on the right side of the window appears Type=[isam], with the mouse point in it, Select InnoDB after the type below the window, and finally click the "Apply to ..." button to select all the tables.
5, create a table when modifying the field, modify the name of the content, code also changes, how to let code does not change with the name
There is a button "=" on the right side of name and code, so if you need to get out of sync, just pop the button up.
Tools->general Options->dialog->name to Code mirroring (remove)
6. Auto-generated foreign key renaming when PDM is generated by CDM
PDM Generation OPTIONS->DETAIL->FK Index names default is%REFR%_FK, change to fk_%refrcode%, where%refrcode% Refers to the code! of relationship in CDM In addition, the rules for automatically generated parent fields are set in the PDM Generation OPTIONS->DETAIL->FK column name template, which is%.3:parent%_%column% by default and can be changed to par% column% represents the parent field!
7. mysql version cannot generate view problem
After you open PDM using MySQL5.0, select the Database->edit current DBMS in the menu.
Confirm that the DBMS is using MySQL5.0
Open the left-hand tree structure Script->objects->view
Select Create to write to value in the right end
Create VIEW [%r%?[if not exists]]%view%
As
%sql%
Check drop to write to value in the right end
drop table if exists%view%
Check Enable to select Yes on the right side of value
OK to save.
Note that this modification modifies the settings of the PowerDesigner program only once, but it does not make changes to the PDM file, and there are no modified powerdesigner that cannot generate the SQL for the view.
8. Why do I detect a warning that existence of index appears after setting up a table
A table should contain at least one column, one index, one key, and one reference.
You can not check existence of index This, there is no such warning error!
It means that the table is not indexed, and a table generally has at least one index, this is a warning, no tube is not related!
9. Error (Oracle) Occurs when a field exceeds 15 characters when generating a table script from PDM
The reason is unknown, the solution is to open the PDM, the database will appear in the menu bar, into the Database-edit current Dbms-script-objects-column-maxlen, the value is adjusted to large (formerly 30), For example, change to 60. This error can be found in the length of the table or other object, either by selecting the corresponding objects, or by using this method:
- The database generation hint box pops up when the build table script is generated: The Options-check model's small tick is removed, is not checked (not recommended)
- You can modify the C:Program filessybasepowerdesigner Trial 11Resource filesdbmsoracl9i2.xdb file. When the CDM is converted to PDM, select "Copy the DBMS The definition in model "copies this resource file into the model.
10, how to prevent a one-to-two relationship to generate two references (foreign key)
To define the dominant direction of the relationship, the dominant entity (with the D flag) becomes the parent table.
Double-click on one-to-one relationship in CDM->detail->dominant role selection domination relationship
11. Do you bother to generate the MSSQL database table directly from the model without the accompanying comment?
PowerDesigner This tool can support the model design of any relational database, because the attribute definitions of each database model in PowerDesigner are stored in a xdb file, and we can do so in [Powerdesigner_install_ Home]/resource Files/dbms can be found below. Of course, we can also create a new xdb ourselves, defining the characteristics of the database model we want to support. Having understood this, the answer to this question is obvious.
Let me just briefly explain that I am using POWERDESINGER11 Enterprise Edition. Please note that there are some simplified versions of Sybase (such as SQL Moduler) that cannot be customized xdb.
- From the menu Tools->resouces->dbms, go to custom data model
- PowerDesigner pops up a dialog box listing the database models supported by the current PowerDesigner. We chose to create a new one. Enter the name SQL Server (EXTENDED) and select Copy from existing SQL Server 2000, so that SQL Server EXTENDED contains all the features that were owned by the original SQL SERVER2000 model.
- Next, we need to add features that support the automatic generation of table and column comment codes for SQL Server Extended. Powerdesinger organizes the defined features in a tree-like structure, and the task of this article is to define script code features. We need to modify the script feature code in Script\objects\table\tablecomment and Script\objects\column\columncomment.
- SQL Server 2000 saves table and column annotations in the database by calling the system stored procedure sp_addextendedproperty. Then we just need to write it separately.
The table-level comment code is:
EXECUTE sp_addextendedproperty n ' ms_description ', n '%comment% ', n ' user ', n '%owner% ', n ' table ', n '%table% ', NULL, NULL
The comment code for the column level is
EXECUTE sp_addextendedproperty n ' ms_description ', n '%comment% ', n ' user ', n '%owner% ', n ' table ', n '%table% ', n ' column ', n '%column% '
Look at the code, and we'll see what's going on right away. %comment% is equivalent to the substitution variable, PowerDesigner automatically replaces the value of the replacement variable in the design model when the script is generated.
- Save SQL Server (Extended) into a xdb file.
- Now, we can create a new physical data model, with database models selected for SQL Server (Extended). To create a table, you need to be reminded that you must specify a database user, typically with dbo. We can add comments to both the table and the column.
- Create a Build library script, menu Databases->generate database. Note To select the comment option. Click OK to get the final build script. Open it up and we see that Powerdesinger generated the corresponding code according to the rules we told it.
EXECUTE sp_addextendedproperty n ' ms_description ', n ' Employee information ', n ' user ', n ' dbo ', n ' table ', n ' employee ', NULL, NULL
Go
EXECUTE sp_addextendedproperty n ' ms_description ', n ' primary key ID, auto increment ', n ' user ', n ' dbo ', n ' table ', n ' Employee ', n ' column ', n ' EmployeeID '
Go
- We execute this corner in SQL Server 2000, and we can see these annotations through Enterprise Manager.
12, the name listed in the scrip display
Modify the field generation rule. To add a comment to each field, expand the value of add in the same window with Column-----Object-----to:
%20:column% [%compute%?as (%compute%):%20:datatype% [%identity%?%i dentity%:[%null%][%notnull%]][default%default%]
[[Constraint%constname%] Check (%constraint%)]]/*%colnname%*/
Where%colnname% is the name value of the column (can be in Chinese)
13, self-growing column settings
In PDM, view the properties of the table, Columns tab, select the whole column, view the column properties, click the property icon (the one with the hand pattern) at the top left, and then open a settings window and set it up in the General tab.
On the General tab of the column properties, there is an identity check box, tick the line.
PowerDesigner use of the detailed