Database meta information, views and administration Flashcards

1
Q

How can you show all databases available

A

SHOW DATABASES;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which query shows all the info for all the catalogs and tables

A

SELECT * FROM INFORMATION_SCHEMA.COLUMNS;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

which query shows all the tables in all a databases?

A

SHOW TABLES FROM database_name;

or

USE database_name
SHOW TABLES;

or

EXPLAIN table_name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you see all the metadata of a table?

A

DESCRIBE table_name;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is an index?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you create an index?

A
CREATE INDEX name_index
ON User (Name)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a view

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Does the DBMS store the views result or the definition of the view?

A

The definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you create a view?

A

CREATE VIEW view_name AS select_statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Does the view duplicate data?

A

No it has references to the real value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why would you use a view rather than the normal tables?

A

To restrict access or to avoid complicated sql queries to get data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the problems with views?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a temporary table

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens when you update a view

A

The updates are retained in the database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happens when you update a temporary table

A

the updates are not saved anywhere else than in the temporary table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can you manage access to a DB?

A
  1. authorization identifier: user & psw
  2. ownership: can be granted or revoked to users
  3. privileges: actions users are allowed to carry out on a DB
17
Q

How can you show all the users?

A

SELECT user FROM mysql.user;

18
Q

How can you show users, hosts they can connect from and password?

A

SELECT user,host,password FROM mysql.user;

SELECT * FROM mysql.user;

19
Q

How can you show all the privileges given to a user?

A

SHOW GRANTS FOR USER;

20
Q

How do you grant and revoke privileges?

A

GRANT INSERT on Employee

to receptionist

21
Q

How can you show the current user logged in?

A

SELECT current_user();

22
Q

How can you log into a user in MySQL?

A

In Workbench, when you chose the database to connect to, create a new connection and put in the user and password instead of root.

23
Q

How do you create users?

Do you need a privilege?

A

You need the CREATE USER and GRANT privileges.

The syntax is:
CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘user_password’;

24
Q

How can you modify users?

Do you need a privilege?

A

With the ALTER USER statement:
ALTER USER ‘user’@’hostname’ IDENTIFIED BY ‘newPass’;

You need the CREATE USER or the UPDATE privilege for the MYSQL system schema

25
Q

What is a role in SQL and why do you use them

A

It is a named group of related privileges that can be granted to the user.

You use them to make the process of granting a user privileges

26
Q

What is the syntax for creating a role?

Privileges?

A

CREATE ROLE role_name

global CREATE ROLE or CREATE USER privilege, as well as the CONNECTION_ADMIN privilege

27
Q

What is a block statement?

A

It is a block of multiple statements that are enclosed by BEGIN and END

28
Q

What are the conditional constructs?

A

IF, CASE

29
Q

What are the Loop consturcts?

A

WHILE, REPEAT, LOOP