Databases Reference
In-Depth Information
To run a script in MySQL, type the SOURCE command followed by the name of the file and then press
the Enter key. For example, to run a script named MySQL-Premiere, you would type the following command:
SOURCE MySQL-Premiere
Before typing commands in MySQL, you must activate the database by typing the USE command fol-
lowed by the name of the database; for example, to activiate the Premiere Products database, the command is
USE PREMIERE. After the database is activated, all commands are assumed to pertain to the activated
database. To activate a different database during the current session, you execute the USE command again with
the new database name. After typing any MySQL command, press the Enter key. MySQL moves the cursor to
the next line and displays the continuation indicator (->). After typing the last line of a command, type a
semicolon and then press the Enter key to execute the command and display the results.
As you are working in MySQL, the most recent command you entered is stored in a special area of memory
called the statement history . You can edit the command in the statement history by using the editing keys
shown in Table 3-1.
71
Activity
Editing Key
Move up a line in the statement history
Up arrow
Move down a line in the statement history
Down arrow
Move left one character within a line
Left arrow
Move right one character within a line
Right arrow
Move to beginning of a line
Ctrl + A
Move to end of a line
Ctrl + E
Delete previous character
Backspace
Delete character below cursor
Delete
TABLE 3-1 MySQL editing commands
For example, to make a correction in the first line of a command, you can use the Up arrow key to bring
the first line of the incorrect command to the screen, make any necessary changes, and then press the Enter
key. You can then bring the second line to the screen, make any necessary changes, and then press the Enter
key. You can repeat this process for all the lines in the command. If you need to add a new line, just type it
at the appropriate position.
Some of the examples used in this text change the data in the database. If you plan to work through the
examples using MySQL, you should follow the instructions in this section for re-creating the Premiere data-
base prior to starting the next chapter. The version of the database used in subsequent chapters does not reflect
these changes.
TABLE CREATION
You use the SQL CREATE TABLE command to create a table by describing its layout. The word TABLE is
followed by the name of the table to be created and then by the names and data types of the columns (fields)
that make up the table. The rules for naming tables and columns vary slightly from one version of SQL to
another. If you have any doubts about the validity of any of the names you have chosen, you should consult the
manual for your SQL version.
Some common restrictions placed on table and column names by DBMSs are as follows:
The names cannot exceed 18 characters.
The names must start with a letter.
The names can contain only letters, numbers, and underscores (_).
The names cannot contain spaces.
 
Search WWH ::




Custom Search