SQL Flashcards

1
Q

Write a simple select query with a condition and sorting, no join

A
SELECT * 
FROM MyTable
WHERE MyColumn > 50
ORDER BY MyColumn
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write a query with inner join

A
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create a table

A
CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255),
    PRIMARY KEY (PersonID)
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Insert row(s) to a table

A
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

-- If using all the columns you can eliminate the column names
INSERT INTO Customers
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

-- insert into with select
INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country FROM Suppliers;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Update data in a table row

A
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Discuss Join types and show how to use each of them

A

(INNER) JOIN: Returns records that have matching values in both tables
LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table
RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table
FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table

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

Do a group by query with some aggregate

A
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

List SQL data types

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

Show how to use a foreign key and discuss why it’s used

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

Talk about indexes, give an example using one

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

Use some common constraints and show how they are used.

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