Learning Mysql



Download 4.24 Mb.
View original pdf
Page159/366
Date04.08.2023
Size4.24 Mb.
#61806
1   ...   155   156   157   158   159   160   161   162   ...   366
Learning MySQL
174 | Chapter 5:
Basic SQL

mysql> SHOW TABLES FROM music;
+-----------------+
| Tables_in_music |
+-----------------+
| album |
| artist |
| played |
| track |
+-----------------+
4 rows inset sec)
If you’ve already selected the music database with the USE music command, you can use the shortcut:
mysql> SHOW TABLES;
+-----------------+
| Tables_in_music |
+-----------------+
| album |
| artist |
| played |
| track |
+-----------------+
4 rows inset sec)
You can get a similar result by specifying the database name to the mysqlshow program mysqlshow --user=root --password=the_mysql_root_password music
As with SHOW DATABASES, you can’t see tables that you don’t have privileges for. This means you can’t see tables in a database you can’t access, even if you have the
SHOW
DATABASES
global privilege.
The SHOW COLUMNS
statement lists the columns in a table. For example, to check the columns of track, type:
mysql> SHOW COLUMNS FROM track;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| track_id | int) | | PRI | 0 | |
| track_name | char) | YES | | NULL | |
| artist_id | int) | | PRI | 0 | |
| album_id | int) | | PRI | 0 | |
| time | decimal) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
5 rows inset sec)
The output reports all column names, their types and sizes, whether they can be
NULL
,
whether they are part of a key, their default value, and any extra information. Types,
keys,
NULL
values, and defaults are discussed further in Chapter 6. If you haven’t already chosen the music database with the
USE
command, then you can add the database name before the table name, as in music.track
. Unlike the previous
SHOW
statements, you can always see all column names if you have access to a table it doesn’t matter that you

Download 4.24 Mb.

Share with your friends:
1   ...   155   156   157   158   159   160   161   162   ...   366




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

    Main page