d1 - data and database entities Flashcards

1
Q

what will this postgres command do: \l

A

lists your databases

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

what will this postgres command do: \du

A

list of users

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

what will this postgres command do: \c

A

connect to a database

ex. \c

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

what will this postgres command do: \d

A

show details of table

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

what will this postgres command do: \dt

A

show list of tables

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

when using a database and pair programming do we both need to setup the DB?

A

yes! because the DB is only local

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

what should you do before each time you use homebrew to install somehting?

A

update homebrew using: brew update

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

what are some ways to do unique identities in postgres?

A

NOT NULL

UNIQUE

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

what will happen when user inputs something null? How does NOT NULL in postgres effect this?

A

if someone puts some null entity input, an error will occur

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

what will happen when a user inputs something with the same name and identifier? How does UNIQUE in postgres effect this?

A

postgres will check rows to see if something already exists, if so, it’ll throw an error

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

what is postbird?

A

it’s a gui for postgres

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

What does RDBMS stand for?

A

relational database management systems (basically a database)

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

What are some populare RDBMS?

A

oracle
SQL server
MySQL
postgreSQL

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

In postgress when typing what should be in uppercase and what should be in lowercase?

A

usernames should be in lowercase

*if you wrap the password in “ “ you can make it uppercase but sequilize will do it for us so don’t worry too much

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

how do you see who your logged in as in postgres?

A

select CURRENT_USER

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

if there’s an ‘=’ in the name in postgres that’s good, but what if there’s a ‘-‘?

A

’-‘ means that your continuing on the same line. So, make sure you end each line with a ‘;’

to get out of that hit ‘;’ and enter

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

What does SQL stand for?

A

structured query language (a query is a question. in this case we ask the database a question)

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

what does -U stand for in postgres?

A

it stands for user

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

what command do you use to access the PostgreSQL server?

A

psql postgres

20
Q

what does the postgreSQL data type mean: VARCHAR(n)

A

a variable-length character string that lets you store up to n charactars.

21
Q

what does the postgreSQL data type mean: DECIMAL(p,s)

A

a floating point number with p digits and s number of places after the decimal point

22
Q

what does the postgreSQL data type mean: INT

A

INT is a 4-byte integer

23
Q

what does the postgreSQL data type mean: BOOLEAN

A

a boolean value. SQL accepts standard boolean vals true, false, or null

24
Q

what are the postgreSQL boolean values that are accepted?

A

True

  • true
  • t
  • ‘true’
  • ‘yes’
  • ‘y’
  • ‘1’

False

  • false
  • ‘f’
  • ‘no’
  • ‘n’
  • ‘0’
25
Q

What does SELECT * mean?

A

it gives you back all of the rows in postgres table

26
Q

What’s the format to select by columns?

A

SELECT [column] FROM [name]

ex. SELECT name FROM puppies

27
Q

how do you select multiple columns?

A

SELECT name
, age_yrs
, weight_lbs
FROM puppies;

we can also do this on a one liner, but it’s better to do this above when doing multiple especially hundreds of columns

28
Q

what does the WHERE query do?

A

It allows us to filter parts from our SELECT query. When using this be sure to use ‘ ‘ not “ “ otherwise it’ll think you’re looking for uppercase letters

29
Q

How to use a WHERE clause to get a list of values?

A

WHERE [column] IN (‘value1’, ‘value2’, ‘value3’).

30
Q

How to set the order you want to receive info back from postgres?

A

SELECT name, breed FROM puppies

ORDER BY name;

31
Q

When would you use the LIMIT clause? What about OFFSET?

A

when you have millions or a lot of data and you want to limit to a certain number of rows of data returned.

To see next rows after the limit you could use OFFSET

EX. SELECT name, breed
FROM puppies
ORDER BY age_yrs
LIMIT 100 OFFSET 100;

32
Q

What’s the logical operator: ALL

A

TRUE if all of the subquery values meet the condition.

33
Q

What’s the logical operator: AND

A

TRUE if all the conditions separated by AND are TRUE.

34
Q

What’s the logical operator: ANY

A

TRUE if any of the subquery values meet the condition.

35
Q

What’s the logical operator: BETWEEN

A

TRUE if the operand is within the range of comparisons.

36
Q

What’s the logical operator: EXISTS

A

TRUE if the subquery returns one or more records.

37
Q

What’s the logical operator: IN

A

TRUE if the operand is equal to one of a list of expressions.

38
Q

What’s the logical operator: LIKE

A

TRUE if the operand matches a pattern (accepts “wildcards”).

It uses the % sign
ex. NOT LIKE ‘%Shepherd’
% can be put before word, after word, or before and after (it’s like when you search the library database)

39
Q

What’s the logical operator: NOT

A

Displays a record if the condition(s) is NOT TRUE.

40
Q

What’s the logical operator: OR

A

TRUE if any of the conditions separated by OR is TRUE.

41
Q

What’s the logical operator: SOME

A

TRUE if any of the subquery values meet the condition.

42
Q

what is the following comparison operator: <>

A

not equal to

43
Q

What is the following comparison operator: !=

A

not equal to

44
Q

What is the following comparison operator: !< and !>

A

not less than

not greater than

45
Q

What does id SERIAL and PRIMARY KEY do?

A

SERIAL auto assigns an identifier. it’s sequential.

PRIMARY KEY allows the id to be used as a foreign key

46
Q

What’s the syntax to create a new database?

A

CREATE DATABASE «your database’s name» WITH OWNER «your user name»;

47
Q

What does the signifier NUMERIC do?

A

it’s a signifier for the number of things. syntax: NUMERIC(num1, num2)

  • first num is the number of total digits including the decimal
  • second num is the number of decimal places needed

ex. NUMERIC(3, 2) - accepts 2.35