Databases Flashcards

1
Q

How do you add a row to a SQL table?

A

insert into “table-name” (“columns”…)
values ( ‘value’)

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

What is a tuple?

A

A single row of a table, which contains a single record for that relation.

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

How do you add multiple rows to a SQL table at once?

A

INSERT INTO table_name (column1, column2)
VALUES (value1, value2);

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

How do you get back the row being inserted into a table without a separate select statement?

A

adding returning *; at the end

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

How do you update rows in a database table?

A

UPDATE table_name
SET some_column = some_value
WHERE some_column = some_value;

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

Why its important to include a where clause in your update statements?

A

you might update every row

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

How do you delete rows from a database table?

A

DELETE FROM students
WHERE enrolled_status = ‘not_current’;
Optional
ALTER TABLE students
DROP COLUMN history;

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

How do you accidentally delete all rows from a table?

A

By typing delete from *

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

What is SQL and how is it different from languages like JavaScript?

A

SQL (Structured Query Language) is design to managing and manipulating data. It’s not a programing language.

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

How do you retrieve specific columns from a database table?

A

using SELECT “specific-column”
FROM “table-name”

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

How do you filter rows based on some specific criteria?

A

Using where clause.
SELECT column1, column2, …
FROM table_name
WHERE condition;

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

What are the benefits of formatting your SQL?

A

everything looks “clearer”, code is much easier to read

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

What are four comparison operators that can be used in a where clause?

A

,= ,!= , <=, >=

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

How do you limit the number of rows returned in a result set?

A

Using limit clause

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

How do you retrieve all columns from a database table?

A

Using asterisk *

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

How do you control the sort order of a result set?

A

Using order by clause.
SELECT column1, column2, …
FROM table_name
ORDER BY column1, column2, … ASC|DESC;

17
Q

What is a foreign key?

A

Foreign key is a link in one table that refers to the primary key in another table .

18
Q

How do you join two SQL tables?

A

Using join clause followed by table-name

19
Q

How do you temporarily rename columns or tables in a SQL statement?

A

Using alias e.g “a”.”table-name”

20
Q

What are some examples of aggregate functions?

A

avg(), count(), min(), max(), sum(),

21
Q

What is the purpose of a group by clause?

A

The purpose of a group by clause is to group results by one or more column.
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);

22
Q

What is PostgreSQL and what are some alternative relational databases?

A

Open Source relational database management system that store data and provides access to data points that are related to one another. Alternative are NoSQL databases which store data using mechanism different than tabula relationship for example using data structure key=value pairs

23
Q

What is one way to see if PostgreSQL is running?

A

Command sudo service postgresql status

24
Q

What is database schema?

A

It’s a collection of tables, it defines how data in relational database should be organized.

25
Q

What is a table?

A

A table is a collection of data organized into rows and columns. Tables are sometimes referred to as relations.

26
Q

What are clauses in SQL?

A

Clauses perform specific tasks in SQL. By convention, clauses are written in capital letters. Clauses can also be referred to as commands.

27
Q

What is SELECT used for?

A

SELECT is a clause that indicates that the statement is a query. We will use SELECT every time you query data from a database.

28
Q

What is ALTER used for?

A

The ALTER TABLE statement adds a new column to a table. You can use this command when you want to add columns to a table. The statement below adds a new column twitter_handle to the celebs table.
ALTER TABLE students
ADD exam_grade INT(3);

29
Q

What is ADD COLUMN used for?

A

ADD COLUMN is a clause that lets you add a new column to a table:
ALTER TABLE friends
ADD COLUMNT email;

30
Q

What is UPDATE USED FOR?

A

UPDATE is a clause that edits a row in the table.
UPDATE players
SET twitter_handle = ‘@akiz333’
WHERE id = 3;

31
Q

What are constraints used for?

A

Constraints in SQL are the rules applied to the values of individual columns. They add information about how a column can be used after specifying the data type for a column. They can be used to tell the database to reject inserted data that does not adhere to a certain restriction.
CREATE TABLE celebs (
id INTEGER PRIMARY KEY,
name TEXT UNIQUE,
grade INTEGER NOT NULL,
age INTEGER DEFAULT 10
);

32
Q

What is relational database?

A

A relational database is a database that organizes information into one or more tables.