MySQL Flashcards

1
Q

Working with Command Line Client (if the MySQL workbench doesn’t work)

A

show databases;
use world;
show tables;
SELECT * FROM City LIMIT 10;

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

Clients + Servers (store files and databases) located on the same network

A

LAN (local area network)
WAN (wide area network) means 2+ networks are in the same geographical area

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

Primary key

A
  • Cannot be Null
  • One per table
  • Unique identifier of row
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Unique key

A
  • Can have one Null
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Datatypes

A

String - CHAR, VARCHAR
Integer - INT
Float - FLOAT
Date and time - DATE

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

Select current date and time / date / time

A

SELECT NOW();
SELECT CURDATE();
SELECT CURTIME();

SELECT SQRT(25);

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

Create a default database

A

USE sakila;
SELECT *
FROM actor;

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

Display the column names only (trick)

A

SELECT *
FROM sakila.actor
WHERE 1 = 2;

Note, 1 is never equal to 2, so it won’t show any data except for the column names

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

Rounding etc

A

SELECT amount,
ROUND(amount) Amnt,
ROUND(amount, 1) Amnt1,
FLOOR(amount) FloorAmnt,
CEILING(amount) CeilingAmnt
FROM sakila.payment;

Floor rounds down to the nearest integer.
Ceiling rounds up to the nearest integer.

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

Concatination

A

SELECT CONCAT(first_name, ‘ ‘, last_name) AS FullName
FROM sakila.actor;

SELECT CONCAT(LEFT(first_name,1), ‘ ‘, LEFT(last_name,1)) AS FirstInitial
FROM sakila.actor;

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

Length of the string

A

SELECT LENGTH(CONCAT(first_name, ‘ ‘, last_name) AS length
FROM sakila.actor;

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

Selecting date format

A

SELECT DATE_FORMAT(last_update, ‘%m/%d/%Y’
FROM sakila.actor;

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

Selecting only unique rows

A

SELECT DISTINCT first_name
FROM sakila.actor;

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

Insert row/rows

A

INSERT INTO sakila.my_table (first_name, last_name, last_update)
VALUES (‘Pinal’, ‘Dave’, ‘2023-04-15’),
(‘Pinal2’, ‘Dave2’, ‘2023-04-16’);

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

Update (change) row/rows

A

UPDATE sakila.actor
SET first_name = ‘Pinal’,
last_name = ‘Dave’
WHERE actor_id IN (3,5,6);

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

DELETE

A

DELETE
FROM sakila.actor
WHERE actor_id = 1;