SQL Flashcards

1
Q

SQL is a standard language for _____________ in databases.

A

storing, manipulating and retrieving data

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

SQL stands for ___________

A

Structured Query Language

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

RDBMS stands for _________________

A

Relational Database Management System.

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

Most of the actions you need to perform on a database are done with ____________

A

SQL statements.
SELECT * FROM Customers;

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

___ - extracts data from a database
____ - updates data in a database
____ - deletes data from a database
______ - inserts new data into a database
______ - creates a new database

A

SELECT
UPDATE
DELETE
INSERT INTO
CREATE DATABASE

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

___ - modifies a database
____ - creates a new table
____ - modifies a table
____ - deletes a table
____ - creates an index (search key)
_______ - deletes an index

A

ALTER DATABASE
CREATE TABLE
ALTER TABLE
DROP TABLE
CREATE INDEX
DROP INDEX

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

The _____ statement is used to select data from a database.

A

SELECT

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

Syntax of Select:

A

SELECT column1, column2, …
FROM table_name;
SELECT CustomerName, City FROM Customers;

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

If you want to return all columns, without specifying every column name, you can use the ______ syntax

A

SELECT *
SELECT * FROM Customers;

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

The ________statement is used to return only distinct (different) values.

A

SELECT DISTINCT

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

The ____ clause is used to filter records.

A

WHERE
SELECT * FROM Customers
WHERE Country=’Mexico’;

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

The ____ BY keyword is used to sort the result-set in ascending or descending order.

A

ORDER
SELECT * FROM Products
ORDER BY Price;

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

The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the ___ keyword.

A

DESC
SELECT * FROM Products
ORDER BY Price DESC;

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

For ____ values the ORDER BY keyword will order alphabetically:

A

string

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

To sort the table reverse alphabetically, use the ___ keyword:

A

DESC
SELECT * FROM Products
ORDER BY ProductName DESC;

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

Using Both ASC and DESC:

A

SELECT * FROM Customers
ORDER BY Country ASC, CustomerName DESC;

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

The WHERE clause can contain one or many ____ operators.

A

AND/OR

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

The AND operator is used to ____ records based on more than one condition, like if you want to return all customers from Spain that starts with the letter ‘G’:

A

filter

SELECT * FROM Customers
WHERE Country = ‘Spain’ AND CustomerName LIKE ‘G%’;

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

OR operator syntax

A

SELECT *FROM Customers
WHERE Country = ‘Germany’ OR Country = ‘Spain’;

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

The ____ operator is used in combination with other operators to give the opposite result, also called the negative result.

A

NOT

SELECT * FROM Customers
WHERE NOT Country = ‘Spain’;

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

Select customers that does not start with the letter ‘A’

A

SELECT * FROM Customers
WHERE CustomerName NOT LIKE ‘A%’;

22
Q

Select customers with a customerID not between 10 and 60:

A

SELECT * FROM Customers
WHERE CustomerID NOT BETWEEN 10 AND 60;

23
Q

Select customers that are not from Paris or London

A

SELECT * FROM Customers
WHERE City NOT IN (‘Paris’, ‘London’);

24
Q

Select customers with a CustomerId not greater than 50:

A

SELECT * FROM Customers
WHERE NOT CustomerID > 50;

25
Q

Select customers with a CustomerID not less than 50:

A

SELECT * FROM Customers
WHERE NOT CustomerId < 50;

26
Q

The ________ statement is used to insert new records in a table.

A

INSERT INTO Customers (CustomerName, ContactName)
VALUES (‘Cardinal’, ‘Tom B. Erichsen’);

27
Q

The ______ operator is used to test for empty values (NULL values).

A

IS NULL

SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NULL;

28
Q

The _________ operator is used to test for non-empty values (NOT NULL values).

A

IS NOT NULL

SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NOT NULL;

29
Q

The _____ statement is used to modify the existing records in a table.

A

UPDATE

UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition;

30
Q

Be careful when updating records. If you omit the ____ clause, ALL records will be updated!

A

WHERE

31
Q

The _____ statement is used to delete existing records in a table.

A

DELETE
DELETE FROM table_name WHERE condition;

DELETE FROM Customers WHERE CustomerName=’Khan anas’;

32
Q

SQL statement deletes all rows in the “Customers” table, without deleting the table:

A

DELETE FROM Customers;

33
Q

To delete the table completely, use the _______ statement:

A

DROP TABLE

DROP TABLE Customers;

34
Q

The ___________ clause is used to specify the number of records to return.

A

SELECT TOP

SELECT TOP 3 * FROM Customers;

35
Q

MySQL Syntax:

A

SELECT column_name(s)
FROM table_name
WHERE condition
LIMIT number;

36
Q

Select the first 3 records of the Customers table: (MySQL)

A

SELECT * FROM Customers LIMIT 3;

37
Q

Oracle 12 Syntax:

A

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s)
FETCH FIRST number ROWS ONLY;

38
Q

Select the first 3 records of the Customers table: (Oracle)

A

SELECT * FROM Customers
FETCH FIRST 3 ROWS ONLY;

39
Q

SQL Server / MS Access Syntax:

A

SELECT TOP number|percent column_name(s)
FROM table_name
WHERE condition;

40
Q

The SQL statement selects the first 50% of the records from the “Customers” table: (for SQL Server/MS Access):

A

SELECT TOP 50 PERCENT * FROM Customers;

41
Q

The SQL statement selects the first three records from the “Customers” table, where the country is “Germany” (for SQL Server/MS Access):

A

SELECT TOP 3 * FROM Customers
WHERE Country=’Germany’;

42
Q

Add the ___________ keyword when you want to sort the result, and return the first 3 records of the sorted result.

For SQL Server and MS Access:

A

ORDER BY
SELECT TOP 3 * FROM Customers
ORDER BY CustomerName DESC;

43
Q

Add the ORDER BY keyword when you want to sort the result, and return the first 3 records of the sorted result.

For MySQL:

A

SELECT * FROM Customers
ORDER BY CustomerName DESC
LIMIT 3;

44
Q

Add the ORDER BY keyword when you want to sort the result, and return the first 3 records of the sorted result.

For oracle:

A

SELECT * FROM Customers
ORDER BY CustomerName DESC
FETCH FIRST 3 ROWS ONLY;

45
Q

An aggregate function is a function that performs a ________ on a set of values, and returns a ______ value.

A

calculation
single

46
Q

The most commonly used SQL aggregate functions are:

MIN() - returns the ____ value within the selected column
MAX() - returns the _______ value within the selected column
COUNT() - returns the ________
SUM() - returns the _______
AVG() - returns the _________ of a numerical column

A

smallest
largest
number of rows in a set
total sum of a numerical column
average value

47
Q

Find the lowest price in the Price column:

A

SELECT MIN(Price)
FROM Products;

48
Q

Find the highest price in the Price column:

A

SELECT MAX(Price)
FROM Products;

49
Q

To give the column a descriptive name, use the ___ keyword:

A

AS
SELECT MIN(Price) AS SmallestPrice
FROM Products;

output:
SmallestPrice
2.5

50
Q
A