Creating a networked data model
In this last exercise, you will create a networked data model. A use case for this is finding all possible paths a bus can take from one location to another. Each route has a departure and destination location. A departure and destination location can appear multiple times. In the following image you can see the possible bus locations and routes. For example, you can go from San Francisco to New York, or from New York to Washington.

Your task is to create the Trip table, insert some routes into this table, and finally, select all possible departure locations from the table.
Bu egzersiz
Hierarchical and Recursive Queries in SQL Server
kursunun bir parçasıdırEgzersiz talimatları
- Define the fields
DepartureandDestination, neither of which can beNULL. - Insert the route from
San FranciscotoNew YorkforBus 1. - Insert the route from
FloridatoSan FranciscoforBus 9. - Select all possible departure locations.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
CREATE TABLE Trip (
-- Define the Departure
___ VARCHAR(255) ___ ___,
BusName VARCHAR(255) NOT NULL,
-- Define the Destination
___ VARCHAR(255) ___ ___,
);
-- Insert a route from San Francisco to New York
___ ___ ___ VALUES ( ___ , ___ , ___);
-- Insert a route from Florida to San Francisco
___ ___ ___ VALUES ( ___, ___ , ___);
INSERT INTO Trip VALUES ( 'San Francisco', 'Bus 2','Texas');
INSERT INTO Trip VALUES ( 'San Francisco', 'Bus 3','Florida');
INSERT INTO Trip VALUES ( 'San Francisco', 'Bus 4','Washington');
INSERT INTO Trip VALUES ( 'New York', 'Bus 5','Texas');
INSERT INTO Trip VALUES ( 'New York', 'Bus 6','Washington');
INSERT INTO Trip VALUES ( 'Florida', 'Bus 7','New York');
INSERT INTO Trip VALUES ( 'Florida', 'Bus 8','Toronto');
-- Get all possible departure locations
SELECT ___ ___
FROM ___;