23 Web Development Exercise 7-1

Web Development Exercise 7-1

In this project, you will create a database to contain tables of batting
statistics for major league baseball teams. You will then create a table
named teamstats in the baseball_stats database and add records
to the new table from a ?le named team_stats.txt in your Projects

1. Log in to MySQL Monitor with your root account or with the

user name and password supplied by your ISP or instructor.
2. Enter the following command to create a database named
baseball_stats:
mysql> CREATE DATABASE baseball_stats;[ENTER ]

3. After you see the “Query OK” message, enter the following
command to select the baseball_stats database:
mysql> USE baseball_stats;[ENTER ]

4. After you see the “Database changed” message, type
the following command to ensure that you selected the
baseball_stats database:
mysql> SELECT DATABASE();[ENTER ]

5. Enter the following command to create the teamstats table.
The Team ?eld uses the VARCHAR data type. Eleven of the col- 439
umns use INT data types, and the remaining two ?elds use
FLOAT data types. Each of the statistical ?eld names uses com-
mon baseball abbreviations, such as G for games, AB for at-
bats, R for runs, and HR for home runs.
mysql> CREATE TABLE teamstats (Team VARCHAR(50),
FirstYear INT,[ENTER ]
-> G INT, W INT, L INT, Pennants INT, WS INT,[ENTER ]
-> R INT, AB INT, H INT, HR INT, AVG FLOAT,[ENTER ]
-> RA INT, ERA FLOAT);[ENTER ]

6. After you see the “Query OK” message, enter the following
command to display the structure of the new table:
mysql> DESCRIBE teamstats;[ENTER ]

7. Enter a LOAD DATA statement that inserts records from the
team_stats.txt ?le in your Projects directory for Chapter 7
Use the
into the teamstats table. Replace path_to_PHP_folders with
MySQL serv-
the full path for your PHP_Projects directory for Chapter 7. er’s direc-
mysql> LOAD DATA INFILE ‘path_to_PHP_folders/ tory path,
Chapter.07/Projects/team_stats.txt'[ENTER ] not the Web
-> INTO TABLE teamstats;[ENTER ] URL path.

8. After you see the “Query OK” message, enter the following
command to view all the records in the teamstats table:
mysql> SELECT * FROM teamstats;[ENTER ]

“0.

Discount Code: 0

: +1 0 0-0

0..