Powerdesigner sets the table primary key column to automatically grow.

Source: Internet
Author: User
Tags powerdesigner

Powerdesigner version 12.5

 

Create a table. The following describes how to set auto-increment columns.

 

1. Create a column in the table view.
Double-click table view to Open Table properties ---> columens,
Double-click the column to be set (the button that displays the sequence number of the column, and a black arrow is displayed ).
Open the column Properties dialog box.

Find the sequence drop-down box at the bottom of the 'general 'item, followed by three buttons 'create', 'select', 'properties '.

Click 'create' to open the sequence Properties dialog box, and modify the name and code in general.
Switch to physical options and enter the following items.
Start with 1
Increment by 1
Minvalue 1
Maxvalue depends on your needs. If no, select no max value.
No cache check

After entering the information, click application. The creation is complete. The corresponding creation code is displayed in the preview.
In addition, the trigger creation code is automatically added to the table properties ---> preview creation code.
Created successfully.

Usage:

Copy the table creation code to table properties ---> preview and copy it to PLSQL for execution.

Tip:

I don't know whether it is my powerdesigner settings or what is going on. The sequence creation section is not automatically added to the table creation code.
Therefore, we need to copy the sequence creation code to the table creation code in sequence properties ---> preview.
Put it in the center of cteate table... and create trigger...

For example:
Create Table g_ec_lotterycategory (
Lcid number (3) not null,
Lcname nvarchar2 (30 ),
Lcabbr nvarchar2 (20 ),
Constraint pk_g_ec_lotterycategory primary key (lcid)
)
/

Create sequence sequence_lotcateid
Increment by 1
Start with 1
Nomaxvalue
Minvalue 1
Nocache;

Create trigger tib_g_ec_lotterycategory before insert
On g_ec_lotterycategory for each row
Declare
Integrity_error exception;
Errno integer;
Errmsg char (200 );
Dummy integer;
Found Boolean;

Begin
-- Column lcid uses sequence sequence_lotcateid
Select sequence_lotcateid.nextval into: New. lcid from dual;

-- Errors handling
Exception
When integrity_error then
Raise_application_error (errno, errmsg );
End;
/
Execute the upper-end code in PLSQL. Create a table;
Add record test;
Insert into g_ec_lotterycategory (lcname, lcabbr) values ('1', '1 ');
Insert into g_ec_lotterycategory (lcname, lcabbr) values ('2', '2 ');

After the query, the ID column is automatically increased.

2. Create it first, and then select it from the sequence item of the column.
In the left Tree of powerdesigner, sequence exists in the sub-menu of your model project, right-click and choose --> New
Open the sequence Properties dialog box and add the content. The above method is similar.
After the completion, go to the table view and double-click the column name to open the column Properties dialog box.
General --> the created sequence is displayed in the sequence drop-down box. Select and save the sequence.
 
The preceding method applies to Oracle databases.

If you are creating a MySQL database model, Open Table properties and double-click columens. In the 'general 'field, check the check box for identity.

 

 

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.