Results: 1022
USE database
Selects the specified database so that after running the query we don't need to specify the database for other queries related to the specified one
USE university
For example we can list all columns from any of the table inside the selected database without specifying it. MySQL will know that we mean already the selected database
SHOW COLUMNS FROM students
Lists all the columns from students table
DESCRIBE students
Note: the query above is alternative and shortcut of
SHOW COLUMNS FROM students
SHOW COLUMNS from a table with specifying a database
Lists all the columns from
students
table that is in the
university
database
SHOW COLUMNS FROM university.students
Another method to specify a database when listing columns from a table
SHOW COLUMNS FROM students IN university
Lists all the columns from the specified table
SHOW COLUMNS FROM students
Shortcut of the query above is
DESCRIBE
DESCRIBE students
Lists all the tables from the specified MySQL database
UniversityDB
SHOW TABLES FROM UniversityDB
SHOW SCHEMAS
Lists all the databases on the MySQL host:
SHOW SCHEMAS
Note: The above query is a synonym for
SHOW DATABASES
Shows all the databases that the current user has access to
SHOW DATABASES
The following query is a synonym of the above query. Both of them list all the databases on the MySQL host:
SHOW SCHEMAS
UNION DISTINCT
combines the two results and removes duplicates
SELECT *
FROM students
WHERE id < 10
UNION DISTINCT
SELECT *
FROM students
WHERE id > 5
The query is equivalent to the above query because
DISTINCT
is the default behavior
SELECT *
FROM students
WHERE id < 10
UNION
SELECT *
FROM students
WHERE id > 5
TRUNCATE
Deletes all the rows from
notes
table
TRUNCATE notes;
The same as the query above - deletes all rows
TRUNCATE TABLE notes;
Note: The two queries are aliases for each other
Deletes the table
notes
with its content
DROP TABLE notes;
If the table does not exist, it will generate the following error:
#1051 - Unknown table 'notes
Deletes several tables at the same time
DROP TABLE notes, students;
Deletes the table if exists, otherwise it will not generate an error
DROP TABLE IF EXISTS notes;
Note: There is no undo. Once we delete, the table is gone
Results: 1022