Design Physical Model 1 in PowerDesigner -- tables and primary foreign keys

Source: Internet
Author: User

The following methods are used to create a physical model in PD:

  1. Directly create a physical model.
  2. Design the conceptual model, and then generate the physical model from the conceptual model.
  3. Design the logical model, and then generate the physical model from the logical model.
  4. Use reverse engineering to connect to an existing database and generate a physical model from the database.

The physical model can intuitively reflect the structure of the current database. Database objects such as tables, views, and stored procedures in databases can be designed in physical models. Due to the consistency between the physical model and the database, the following describes the correspondence between the database object and the physical model object:

Table

When creating a physical model, you must specify the DBMS corresponding to the physical model. Here we use SQL Server 2008. After creating a new physical model, the system will display a toolbar dedicated to the physical model design:

To add a table to the physical model, click the "table" button and click "Model Design" to add a table. The system name is Table_n by default, here, n will increase as the number of tables added increases. The added table does not contain any columns ,:

Click the mouse pointer button on the toolbar, switch the mouse back to the pointer mode, and double-click a table. The system opens the table Properties window. On the General tab, you can set attributes such as Name and Code of the table. For example, to create a new ClassRoom table (ClassRoom), you can modify the Name and Code. Name is the Name displayed in the model, and Code is the actual table Name when the database table is generated. In addition, the content in Name is also used as the table remarks in SQL Server.

Click Columns to switch to the Columns tab. You can add Columns in the table in the following list. The Name is the Name displayed on the model, and the Code is the actual table Name generated. The three check boxes "P" follow indicate the primary key, and "F" indicate the foreign key, and "M" indicates that the value cannot be blank. Two columns are designed for the classroom table ,:

 

Primary Key

When designing a table, each table usually has a primary key, which is divided into a single column primary key and a composite primary key. You can set a primary key for a table in the following ways:

1. On the Columns tab, select the P column check box of the primary key column. This is the easiest way.

2. select a column and click the "attribute" button in the toolbar. The column attribute window is displayed, in which you can set various attributes of the column, of course, it also includes whether the column is a primary key. Another important check box is "Identity ". If you select the "Identity" check box, this column is an auto-incrementing column.

3. switch to the Keys tab, add a row named PK_ClassRoom, and click the "properties" button in the toolbar to open the key Properties window, switch to the Columns tab, and click Add column, in the pop-up Column Selection window, select the columns that should be included in the primary key and click OK to create the primary key.

In addition, when a primary key is created, the system creates an index on the primary key. indexes are classified into clustered indexes and non-clustered indexes, on the General tab of the "Key properties" window, you can set whether the index created on the primary key is a clustered index or a non-clustered index ,:

Foreign key

If the physical model is generated by the conceptual or logical model, the foreign key is generated through Relationship, or the Reference in the toolbar can be used to implement the foreign key Relationship between the two tables. If a course only takes classes in a fixed classroom and multiple courses are arranged in a single classroom at different times, the relationship between the classroom and the course is one-to-many, in the curriculum, you need to add the RoomID column to form a foreign key column. The specific operation is to click the "Reference" button in the toolbar, and then in the design panel, press the left mouse button on the curriculum, drag the mouse to the instructor table. If no RoomID Column exists in the course list, the system automatically creates the RoomID column and creates a foreign key reference for the column. If the RoomID column already exists, only foreign key references are added, and no new columns are added.

Switch to the mouse pointer mode, double-click the arrow, and the system will pop up the referenced Property Window, in the Properties window, you can set the referenced Name, Code, associated columns, constraint names, update policies, and deletion policies.

The next article will introduce other constraints, including:

1. CHECK Constraints

2. Default Value Constraints

3. Non-empty Constraint

......

In addition, the physical model also includes views, stored procedures, functions, and triggers, which will be explained in the following articles.

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.