Professional Documents
Culture Documents
How To Create and Query The SP Database
How To Create and Query The SP Database
How To Create and Query The SP Database
Page 1
1. Launch Microsoft MS-DOS command prompt shell window. Hint Click the Windows Start menu |
All Programs | Accessories | Run, then enter cmd in the Open: text box and click the OK button.
2. Navigate to the drive and folder that contains your SQLite3.exe application file, the SQL script files
CreateSPDB.sql and DisplaySP.sql, and your SQL Problem Set SQL script files.
3. Enter the MS-DOS command SQLite3 SP.db to launch the SQLite application and create the empty
database named SP.db.
4. Enter the SQLite command .read CreateSPDB.sql which reads in and interprets the SQL script file
that contains the three CREATE TABLE statements and three collections of INSERT statements
required to populate the SP database.
5. Enter the SQLite command .read DisplaySP.sql which reads in and interprets the SQL script file
that contains the SQL SELECT statements required to output the extension (contents) of the three SP
database relations s, p, and sp to the file DisplaySP.log. Hint Use DisplaySP.log to manually compute
the results of your SQL queries to ensure that your syntactially-valid SQL is semantically correct!
6. Enter the SQLite command .quit to terminate SQLite.
);
sname TEXT
status INTEGER
city
TEXT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
s
s
s
s
s
s
s
s
s
NOT NULL
NOT NULL,
NOT NULL
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
);
COLLATE NOCASE,
COLLATE NOCASE
('S01',
('S02',
('S03',
('S04',
('S05',
('S06',
('S07',
('S08',
('S09',
CREATE TABLE p
(
pno
TEXT
pname TEXT
color TEXT
weight INTEGER
cost
REAL
city
TEXT
NOT
NOT
NOT
NOT
NOT
NOT
Page 2
'Smith',
'Jones',
'Blake',
'Clark',
'Adams',
'Garcia',
'Thomas',
'Jonas',
'Zeeman',
NULL COLLATE
NULL COLLATE
NULL COLLATE
NULL,
NULL,
NULL COLLATE
20,'London' );
10,'Paris'
);
30,'Paris'
);
20,'London' );
30,'Athens' );
50,'Austin' );
10,'El Paso' );
40,'New York');
10,'LONDON' );
NOCASE,
NOCASE,
NOCASE,
NOCASE,
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
p
p
p
p
p
p
p
p
p
p
p
p
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
CREATE TABLE sp
(
sno
TEXT
pno
TEXT
qty
INTEGER
dueDate TEXT
('P01',
('P02',
('P03',
('P04',
('P05',
('P06',
('P07',
('P08',
('P09',
('P10',
('P11',
('P12',
NOT
NOT
NOT
NOT
'Nut',
'Bolt',
'Screw',
'Screw',
'Cam',
'Cog',
'Washer',
'Nut',
'Nail',
'Gear',
'Tack',
'Wheel',
'Red',
'Green',
'Blue',
'Red',
'Blue',
'Red',
'Silver',
'Gold',
'Silver',
'Blue',
'White',
'Black',
12.1,
17.3,
17.4,
14.0,
12.9,
19.7,
10.1,
15.3,
16.5,
35.7,
5.6,
97.8,
0.13,
0.25,
0.09,
0.10,
5.26,
3.75,
0.11,
0.13,
0.01,
9.99,
0.01,
2.30,
INTO
INTO
INTO
INTO
INTO
INTO
sp
sp
sp
sp
sp
sp
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
'London' );
'Paris' );
'Rome'
);
'London' );
'Paris' );
'London' );
'El Paso');
'Austin' );
'Rome'
);
'Houston');
'Dallas' );
'Paris' );
('S01',
('S01',
('S01',
('S01',
('S01',
('S01',
'P01',
'P02',
'P03',
'P04',
'P05',
'P06',
300,
200,
400,
200,
100,
100,
'1990-01-01');
'1990-10-19');
'1990-08-07');
'1990-11-11');
'1990-07-11');
'1990-02-10');
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
sp
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
('S01',
('S02',
('S02',
('S03',
('S04',
('S04',
('S04',
('S05',
('S05',
('S05',
('S06',
('S06',
('S08',
('S08',
('S09',
('S09',
('S09',
('S09',
('S09',
('S09',
'P12',
'P01',
'P02',
'P02',
'P02',
'P04',
'P05',
'P01',
'P09',
'P11',
'P02',
'P12',
'P08',
'P11',
'P01',
'P03',
'P04',
'P07',
'P10',
'P12',
50,
300,
400,
200,
200,
300,
400,
50,
150,
320,
150,
825,
180,
250,
100,
200,
100,
300,
100,
200,
Page 3
'1990-12-29');
'1990-06-20');
'1990-03-23');
'1990-12-07');
'1990-05-03');
'1990-04-05');
'1990-11-18');
'1990-03-03');
'1990-04-30');
'1990-05-17');
'1990-10-05');
'1990-06-07');
'1990-09-26');
'1990-07-28');
'1990-02-10');
'1990-08-01');
'1990-01-09');
'1990-08-20');
'1990-12-22');
'1990-09-14');
Page 4
sname
---------Smith
Jones
Blake
Clark
Adams
Garcia
Thomas
Jonas
Zeeman
status
---------20
10
30
20
30
50
10
40
10
city
---------London
Paris
Paris
London
Athens
Austin
El Paso
New York
LONDON
*************************
Relation (p)arts
*************************
pno
---------P01
P02
P03
P04
P05
P06
P07
P08
P09
P10
P11
P12
pname
---------Nut
Bolt
Screw
Screw
Cam
Cog
Washer
Nut
Nail
Gear
Tack
Wheel
color
---------Red
Green
Blue
Red
Blue
Red
Silver
Gold
Silver
Blue
White
Black
weight
---------12.1
17.3
17.4
14
12.9
19.7
10.1
15.3
16.5
35.7
5.6
97.8
*************************
Relation (s)uppliers-of-(p)arts
*************************
sno
---------S01
S01
S01
S01
S01
S01
S01
S02
S02
S03
S04
S04
S04
pno
---------P01
P02
P03
P04
P05
P06
P12
P01
P02
P02
P02
P04
P05
qty
---------300
200
400
200
100
100
50
300
400
200
200
300
400
dueDate
---------1990-01-01
1990-10-19
1990-08-07
1990-11-11
1990-07-11
1990-02-10
1990-12-29
1990-06-20
1990-03-23
1990-12-07
1990-05-03
1990-04-05
1990-11-18
cost
---------0.13
0.25
0.09
0.1
5.26
3.75
0.11
0.13
0.01
9.99
0.01
2.3
city
---------London
Paris
Rome
London
Paris
London
El Paso
Austin
Rome
Houston
Dallas
Paris
P01
P09
P11
P02
P12
P08
P11
P01
P03
P04
P07
P10
P12
50
150
320
150
825
180
250
100
200
100
300
100
200
Page 5
1990-03-03
1990-04-30
1990-05-17
1990-10-05
1990-06-07
1990-09-26
1990-07-28
1990-02-10
1990-08-01
1990-01-09
1990-08-20
1990-12-22
1990-09-14
1. Use your favorite text-editor to develop the SQL script file named ProblemSet1.sql which contains
SQL statements to solve the query problems in SQL Problem Set #1.
2. Launch Microsoft MS-DOS command prompt shell window. Hint Click the Windows Start menu |
All Programs | Accessories | Run, then enter cmd in the Open: text box and click the OK button.
3. Navigate to the drive and folder that contains your SQLite3.exe application file, the SQLite database
file SP.db (created earlier, see above), and your SQL Problem Set #1 SQL script file.
4. Enter the MS-DOS command SQLite3 to launch the SQLite application.
Note Steps 2, 3, and 4 can be short-circuited either by launching the SQLite application by
double-clicking on the file SQLite3.exe (found in the list of files displayed by Windows
Explorer) or by creating a desktop short-cut to the SQLite3.exe application and then doubleclicking on the short-cut.
5. Enter the SQLite command .read ProblemSet1.sql which reads in and interprets the commands
contained in the SQL script file you created in Step 1.
Note Your SQL script file must contain embedded SQLite dot-commands which direct
your query results to a text file that you can send to Dr. Hanna as evidence that your SQL
query commands are correct.
6. Enter the SQLite command .quit to terminate SQLite.
Page 6
sname
---------Smith
Jones
Blake
Clark
Adams
Garcia
Thomas
Jonas
Zeeman
status
---------20
10
30
20
30
50
10
40
10
city
---------London
Paris
Paris
London
Athens
Austin
El Paso
New York
LONDON