tags: powerdesigner Database table creation Primary key Foreign key Unique constraint
I have been using this software to make tables for the past two days. It is really convenient to generate a database with one click. That is, the connection between the unique key of the primary and foreign keys is not understood once, and the information is checked for a long time. Understand. Record it.
1. The default is PowerDesigner 15.1 version.
2. The default generated statement corresponding database is MySQL 5.0
3. Have a basic look directly from where the primary key is.
1. Select the model types and the Physical Data Model below
2. Choose at random in Model name, in DBMS (database model select) in the database, you can choose a variety of corresponding database types, including MySQL, Oracle, SQL server and so on. We choose MySQL here. After all, no money.
1. Translation is a color palette, which can be understood as a tool.

2. Select from top to bottom, create a new table, and associate a foreign key.

1. Click New Table and a table1 appears.
2. Click the mouse arrow to select. Open the table.

3. We create a new student table, student.

4. We fill in some fields and click apply. Here is a brief talk about the difference between UUID and study_id. UUID is automatically generated by directly calling database functions ("SELECT * UUID();" in MySQL). It is a series of 50-bit fields that are never repeated through a series of algorithms based on parameters such as time and equipment. In large batches of data, you can use this feature to get a unique guarantee and use it as the primary key. It is different from any field in the database. The student_id, generally considered to be a student ID, is only unique in this table.
5. Click on keys, and you can see that there is a key_1 in it. This is because there is already a key for the primary key constraint, which is our uuid. We will now create a unique constraint.
6. As shown in the figure, click 1, add a new key, select it, and click 2, Properties. Choose yes.

7. Select MySQL in the pop-up window and select the unique key unique constraint.

8. Select columns 1, click add 2, select the field to be uniquely constrained, student id 3. Click Yes 4.

9. Our student table is built. You can see that there is a PK and primary key behind uuid. There is ak behind the student ID, which is the only constraint. At the same time, we have also built a classroom table with the same field correspondence. According to the actual correspondence, a student has only one classroom, but a classroom can have multiple students, so we can directly add the classroom table as a foreign key to the student table.

10. As shown in the figure, select the foreign key first, and then pull from the student table to the teacher table, the teacher table is automatically added to the student table. Where there is a FK UUID, foreign key.

11. But we don't want the uuid of the classroom table to be the primary key of the student table, and we want the uniquely constrained field of classroom id to be the primary key of the student table.

12. As shown in the figure, we double-click to open the connection relationship and select the join connection. Key Select key_2 The following shows the classroom id, select OK.
13, As shown in the picture, it's done. The classroom id automatically quoted in the student table. (However, the classroom is used as the primary key, you can open the table structure, and just uncheck the P primary key.

14. Open the table structure, look at the preview, and find that the code has been written.

Commonly used to create table statement ...
Several concepts of MySQL: primary key, foreign key, index, unique index concept: Primary key A property or group of attributes that uniquely identifies a row in a table. A table can only have one pri...
Primary key: YesA property or group of attributes that uniquely identifies a row in the table. For example, a record includes the identity positive number, name, and age. The ID number is the only one...
Constraint (constraint): restricted on the columns property sheet is created, the fields. Such as: not null / unique / primary key / foreign key / check Range: ① column-level constraints can act only ...
1. Find out the foreign key according to the prompt delete U_BASE_CONFIG; 2. Find the corresponding subtable by the name of the foreign key 3. Invalidate the foreign key constraint of the subtable U_A...
Article Directory SQL constraints not null unique Primary key FOREIGN KEY SQL constraints Is to constrain the data type of the list The constraints can be specified when the table is created (via the ...
MySQL constraints (primary key, unique, non-empty, foreign key) Concept: Limit the data in the table to ensure the correctness, validity and completeness of the data. classification: 1. Primary key co...
Primary key, foreign key, unique index, single index and composite index A primary key Concept: The primary key is one or more fields in the table, and its value is used to uniquely identify a record ...
Article Directory Create table join constraint Not null constraint (not null) Unique constraint (unique) Primary key constraint (primary key) Foreign key constraint, foreign key Create table join cons...