简体   繁体   中英

Create a new table with each new record

I am building a Hospital Management System and I wanted to make a table in the database that contains all the hospitals. Each hospital has another table that contains info about its employees.

If I wanted to add a new record (a new Hospital) in the hospital table after the system is released, can the system generate a new table for that new hospital's employees?

It would have a standard form and the system would ask the user to fill it (through GUI, or any other way).

Is it technically possible? And if not is there other ways to do it?

Why would you need to create a seperate table for each hospital? Add Hospital_ID as a column to the Employee table and then you can tell, from that one table, what hospital an mployee works for.

SQLFiddle

First you should read about Table relationships . It's really important that you understand how it works before desgnining your database.

Now as for your question, tables don't contain tables. This is why you should review you design.

You should have a those tables :

Hospital 
---------------------------------------------------
| ID |   Name   |       Address     |     Phone    |
---------------------------------------------------
|  1 | SomeName |  13 Mercy Street  | 555-555-5555 |
---------------------------------------------------

Employee
-------------------------
| ID | Hospital_ID | Name |
-------------------------
| 01 |      1      | John |
-------------------------

This way every employee is associated with an hospital. We now know John works in the SomeName hospital.

To help in your research,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM