Database meta information, views and administration Flashcards
How can you show all databases available
SHOW DATABASES;
Which query shows all the info for all the catalogs and tables
SELECT * FROM INFORMATION_SCHEMA.COLUMNS;
which query shows all the tables in all a databases?
SHOW TABLES FROM database_name;
or
USE database_name
SHOW TABLES;
or
EXPLAIN table_name
How can you see all the metadata of a table?
DESCRIBE table_name;
what is an index?
a data structure that stores the values for a specific column.
e.g.
on column name.
now if you have to look for all John names you dont have to look at all rows. An index will store all column names alphabetically and you will only need to search in that
How do you create an index?
CREATE INDEX name_index ON User (Name)
What is a view
It is a virtual table derived from other tables that contain data from those tables - a virtual table that refers to some data in a database.
Does the DBMS store the views result or the definition of the view?
The definition
How do you create a view?
CREATE VIEW view_name AS select_statement
Does the view duplicate data?
No it has references to the real value.
Why would you use a view rather than the normal tables?
To restrict access or to avoid complicated sql queries to get data.
What are the problems with views?
have to be re-run anytime they are referenced because each time you use the name of a view, its table is recreated from existing data - a solution is to store the view as a temporary table making the view last a session - but you have to add the data to the table
What is a temporary table
it is a temporary table that lasts for one session only- You have to create and add data to them every time.
Stored procedures can help you create them easily
What happens when you update a view
The updates are retained in the database
What happens when you update a temporary table
the updates are not saved anywhere else than in the temporary table