Learning Mysql



Download 4.24 Mb.
View original pdf
Page121/366
Date04.08.2023
Size4.24 Mb.
#61806
1   ...   117   118   119   120   121   122   123   124   ...   366
Learning MySQL
Basic SQL

The structure of the music database is straightforward it’s the simplest of our three sample databases. Let’s use the MySQL monitor to explore it. If you haven’t already,
start the monitor using the instructions in Loading the Sample Databases in Chapter. To choose the music database as your current database, type the following:
mysql> USE music;
Database changed mysql>
You can check that this is the active database by typing in the SELECT DATABASE );
command:
mysql> SELECT DATABASE();
+------------+
| DATABASE) |
+------------+
| music |
+------------+
1 row inset sec)
mysql>
Now, let’s explore what tables makeup the music database using the SHOW TABLES
statement:
mysql> SHOW TABLES;
+-----------------+
| Tables_in_music |
+-----------------+
| album |
| artist |
| played |
| track |
+-----------------+
4 rows inset sec)
MySQL reports that there are four tables, which map exactly to the four entities in
Figure 5-1. The
SHOW
statement is discussed in more detail later in Exploring Databases and Tables with SHOW and mysqlshow.”
So far, there have been no surprises. Let’s find out more about each of the tables that makeup the music database. First, let’s use the SHOW COLUMNS
statement to explore the artist table:
mysql> SHOW COLUMNS FROM artist;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| artist_id | smallint(5) | NO | PRI | 0 | |
| artist_name | char) | NO | | | |
+-------------+-------------+------+-----+---------+-------+
2 rows inset sec)
The
DESCRIBE
keyword is identical to SHOW COLUMNS FROM, and can be abbreviated to just
DESC
, so we can write the previous query as follows:

Download 4.24 Mb.

Share with your friends:
1   ...   117   118   119   120   121   122   123   124   ...   366




The database is protected by copyright ©ininet.org 2024
send message

    Main page