I am new to MySql and sql.
i can’t figure out how to do the following:
i have a bus schedule database with four relevant tables:
stops (24,403 rows)
-------------------
stop_id int(11)
stopTimes (12,073,459 rows)
---------------------------
trip_id varchar(30)
stop_sequence int(11) // running sequence within the trip: 1-last
stop_id int(11)
trips (320,395 rows)
---------------------------
trip_id varchar(30)
route_id int(11)
routes (9,748 rows)
---------------------------
route_id int(11)
agency_id int(11)
route_short_name varchar(10)
relations
- routes to trips: one to many
- trips to stopTimes: one to many
- stops to stopTimes: one to one
out of these tables i would like to create a new table “routeStops” with the following fields:
routeStops (~100,000 rows)
---------------------------
route_id int(11)
agency_id int(11)
route_short_name varchar(10)
stop_id int(11)
with a one to many relationship between it and the stops.
is there an SQL query that can perform that?
should i add an index to the route_id and stop_id to optimize performance? should i add a fulltext index to trip_id?
i am new to that and will appreciate some insights.
i am using PHPMyAdmin and a rather new XAMPP installation.
tnx,
Is there an SQL query that can perform that?
You can achieve it using the INSERT … SELECT syntax:
Should I add an index to the route_id and stop_id to optimize performance?
Those should be the primary key in their tables, and a foreign key in the other tables.
Should I add a fulltext index to trip_id?
I don’t recommend it because it would be too slow. I suggest that you alter your tables and use an
intfor the trip_id: