Question: CREATE TABLE political_unit ( unitname VARCHAR(30) NOT NULL, unitcode CHAR(2), unitpop DECIMAL(6,2), PRIMARY KEY(unitcode)); CREATE TABLE boundary ( boundid INTEGER, boundpath POLYGON NOT NULL, unitcode

CREATE TABLE political_unit (

unitname VARCHAR(30) NOT NULL,

unitcode CHAR(2),

unitpop DECIMAL(6,2),

PRIMARY KEY(unitcode));

CREATE TABLE boundary (

boundid INTEGER,

boundpath POLYGON NOT NULL,

unitcode CHAR(2),

PRIMARY KEY(boundid),

CONSTRAINT fk_boundary_polunit FOREIGN KEY(unitcode)

REFERENCES political_unit(unitcode));

CREATE TABLE city (

cityname VARCHAR(30),

cityloc POINT NOT NULL,

unitcode CHAR(2),

PRIMARY KEY(unitcode,cityname),

CONSTRAINT fk_city_polunit FOREIGN KEY(unitcode)

REFERENCES political_unit(unitcode));

INSERT INTO political_unit VALUES ('Spain', 'es', 49);

INSERT INTO political_unit VALUES ('Portugal','pt', 10);

INSERT INTO political_unit VALUES ('Andorra','ad', .086);

INSERT INTO political_unit VALUES ('United Kingdom','uk', 64.51);

INSERT INTO boundary VALUES (3,GeomFromText('POLYGON((12 12, 13 12, 13 11, 12 11, 12 12))'),'ad');

INSERT INTO boundary VALUES (4,GeomFromText('POLYGON((1 10, 4 10, 4 9, 3 3, 1 3, 1 5, 0 5, 0 6, 1 8, 1 10))'),'pt');

INSERT INTO boundary VALUES (5,GeomFromText('POLYGON((1 12, 3 13, 12 12, 12 11, 15 11, 15 11, 11 7, 11 5, 9 2, 5 1, 4 1, 3 3, 4 9, 4 10, 1 10, 1 12))'),'es');

INSERT INTO city VALUES ('Braga',GeomFromText('POINT(2 10)'),'pt');

INSERT INTO city VALUES ('Porto',GeomFromText('POINT(1 9)'),'pt');

INSERT INTO city VALUES ('Lisbon',GeomFromText('POINT(1 5)'),'pt');

INSERT INTO city VALUES ('Santiago de Compostela',GeomFromText('POINT(2 12)'),'es');

INSERT INTO city VALUES ('Oviedo',GeomFromText('POINT(5 12)'),'es');

INSERT INTO city VALUES ('Santander',GeomFromText('POINT(7 12)'),'es');

INSERT INTO city VALUES ('Vitori',GeomFromText('POINT(8 11)'),'es');

INSERT INTO city VALUES ('Pamplona',GeomFromText('POINT(9 11)'),'es');

INSERT INTO city VALUES ('Logrono',GeomFromText('POINT(8 11)'),'es');

INSERT INTO city VALUES ('Valiadoti',GeomFromText('POINT(6 10)'),'es');

INSERT INTO city VALUES ('Saragossa',GeomFromText('POINT(10 10)'),'es');

INSERT INTO city VALUES ('Barcelona',GeomFromText('POINT(13 10)'),'es');

INSERT INTO city VALUES ('Madrid',GeomFromText('POINT(7 8)'),'es');

INSERT INTO city VALUES ('Toledo',GeomFromText('POINT(7 7)'),'es');

INSERT INTO city VALUES ('Valencia',GeomFromText('POINT(11 6)'),'es');

INSERT INTO city VALUES ('Murcia',GeomFromText('POINT(10 4)'),'es');

INSERT INTO city VALUES ('Sevilla',GeomFromText('POINT(4 3)'),'es');

INSERT INTO city VALUES ('Gibralta',GeomFromText('POINT(5 1)'),'uk');

INSERT INTO city VALUES ('Andorra la Veila',GeomFromText('POINT(12 11)'),'ad');

Write the SQL statement to indicate the furthermost Spanish city (i.e., with a unitname = Spain) from Barcelona:

Write the SQL statement to indicate the nearest city if your geographic positioning system (GPS) indicates that your coordinates are (9,11):

Write the SQL statement to generate the list of all the Spanish cities (i.e., with a unitname = Spain) north of Madrid, and order the result in descending order of city name:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!