문제

I have designed my database model with entities and they have relations along with normalization. Now I want to implement my design in my database engine. Before implementing I am puzzled with the order of table creation.

Which pattern should I follow?

  1. the tables with no foreign keys first
  2. the tables with foreign keys

Or would it be better to follow this order:

  1. tables without any foreign keys
  2. tables which are connected with that table

I am new to database design. So forgive me if i am asking this awkward question.

I am implementing my design via mysqlworkbench 8.x

도움이 되었습니까?

해결책

I use to follow this path:

  1. create all table, only structure (fields), without any Primary Keys nor Foreign Key, without any Index, the order doesn't matter

1.1 inject predefined (aka static) datas

  1. create Primary Keys & Indexes

  2. create Constraints if any

  3. finally, create inter-table relations aka Foreign keys

Gains expected:

  • no time spent to manage table order (your primary goal)

    => in the worst case, you can order your tables by an alphabetic order

  • declarations are grouped by meaning (table then PK & Indexes then Constraints then FK), a gain of visibility and accessibility

  • easiest to debug

  • you can store all these items all in one file (for a simple project), or one file by step (big or complex project)

다른 팁

Please follow the below steps that might help you to achieve your desired goal.

  1. create parent tables(for foreign key reference) or any table and define primary keys.

  2. create child tables(for foreign key) and define the foreign key and refer it from the column of parent table.

  3. create indexes on the table.

  1. Create the table with simple structure i.e tables with no foreign keys.
  2. Then create the tables that are going to refer those new tables created.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 dba.stackexchange
scroll top