Reputation: 1561
I am working on fleet management. I want to create one table per vehicle ie when I create a vehicle I want a table to be created for that vehicle at run time. Now I am writing a procedure which creates table but table with same name is not created. How to achieve this?
Any alternative?
Technology: ASP.NET/MYSQL
What If I go for portioning?
Upvotes: 0
Views: 1264
Reputation: 45721
It is indeed, as other people have already said, a VERY bad idea to have one table per vehicle. A much sounder approach would be to create separate tables for separate kinds of vehicles, in case they need to store different data. It could look something like:
vehicles
{vehicle_id, type, name, commission_date, [other data]}
freight_vehicles
{vehicle_id, load_capacity, [other data]}
passenger_vehicles
{vehicle_id, passenger_capacity, [other data]}
assignments
{vehicle_id, from_destination, to_destination,
started_at, finished_at, [other data]}
destinations
{destination_id, name, [other data]}
Since you probably know more about database design than your boss, take the time to prove your case by:
Upvotes: 0
Reputation: 36502
Doing that would be a terrible misuse of a relational database.
Has he got a good reason why you should use that design?
Are there any good reasons why anyone would ever want to do things this way? (I am genuinely interested if there is a valid use case)
Upvotes: 0
Reputation: 65476
You can get the best of both by partitioning the data, but leaving it in one table. See here for an example, and here too
Upvotes: 1
Reputation: 29849
The alternative is to do it the right way - with 1 table that stores all vehicles.
Your boss's solution will make it next-to-impossible to query the database. Explain this to him, and if he still insists that you do it "his way", tell him he's a moron.
Upvotes: 6
Reputation: 33646
this sounds like a very bad idea, but if you insist you can simply send a CREATE TABLE query just like any other query.
create your table once using PHPMyAdmin or a similar tool to see the exact CREATE TABLE command, and use that as the template to create similar tables.
another option is the CREATE TABLE LIKE command, which will create table with the same schema, but without data.
Upvotes: 0