NPM/PostgreSQL Flashcards

1
Q

What is NPM?

A
world's largest software registry. Node Package Manager.
consists of 3 distinct components:
1. the website
2. the Command Line Interface
3. the registry
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a package?

A

reusable codes.
a Node Modules or contain Node Modules.
is a file or directory and a package.json file.

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

How can you create a package.json with npm?

A

npm init –yes

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

What is a dependency and how to you add one to a package?

A
dependency - the other modules that this module uses. to specify the packages your project depends on.
someone else's code, for the project to run on

You can add dependencies to a package.json file from the command line or by manually editing the package.json file.
from command line: npm install [–save-prod]
manually: add an attribute called ‘dependencies’ that references the name and semantic version of each dependency.

{
  "name": "my_package",
  "version": "1.0.0",
  "dependencies": {
    "my_dep": "^1.0.0",
    "another_dep": "~2.2.0"
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens when you add a dependency to a package with npm?

A

the package is automatically added as a dependency

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

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is an open source object-relational database system (relational database system).
alternatives are Microsoft SQL Server, MySQL, Oracle Database. maybes = MongoDB, Redis, Neo4j

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

What are some advantages of learning a relational database?

A

Simple Model. A Relational Database system is the most simple model, as it does not require any complex structuring. Data Accuracy, Easy access to Data. Used very frequently, it’s all shared query language. share the same syntax. compacted very well. good at preventing data duplication. very flexible based on what the data is. Essentially a table

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

What is one way to see if PostgreSQL is running?

A

on terminal enter the command / having the top command.

sudo service postgresql status

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

What is a database schema?

A

is a collection of tables. defines the structure of databas.

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

What is a table?

A

A table is a list of rows each having the same set of attributes. For example, all students in a “students” table could have “firstName”, “lastName”, and “dateOfBirth” attributes. Attributes are commonly referred to as columns

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

What is a row?

A

is the actual record of single data.

the table it defines what each row should have, each row is the instance of the data.

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

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

A

is the primary way of interacting with relational databases. way of retrieving, creating, and manipulating data in a relational database.
it differs from JS which is an imperative programming language, whereas SQL is a declarative programming language. => describes the results they want and the programming environment comes up with its own plan for getting the results (like HTML CSS)

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

How do you retrieve specific columns from a database table?

A

with SELECT keyword
SELECT “attribute” (if more than one ,)
FROM clause “table”

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

How do you filter rows based on some specific criteria?

A

after FROM clause use WHERE clause “column” = > < != ‘field’

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

What are the benefits of formatting your SQL?

A

for consistent style and readability

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

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

A

=, !=, >, <, >= ,<=, < >, BETWEEN

17
Q

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

A

with LIMIT clause (number without ‘’)

18
Q

How do you retrieve all columns from a database table?

A

SELECT (keyword with) *

19
Q

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

A

ORDER BY (clause ) “column” desc. if desc left blank, ascending by default.

20
Q

How do you add a row to a SQL table?

A

INSERT INTO “name of table” (“column”, column”)
VALUES (‘value’, ‘value’)
(‘value’, ‘value’)
RETURNING *;
in the same order as the columns they belong to

21
Q

What is a tuple?

A

a list of values. rows. a record stored in a row

22
Q

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

A

INSERT INTO “name of table” (“column”, column”)
VALUES (‘value’, ‘value’),
(‘value’, ‘value’)
RETURNING *;
in the same order as the columns they belong to

23
Q

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

A

RETURNING *;

can also specify columns with the RETURNING keyword

24
Q

How do you update rows in a database table?

A

update “products”
set “price” = 200,
“name” = ‘Super ShakeWeight’,
“description” = ‘Makes you ULTRA strong!’
where “productId” = 24;

25
Q

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

A

because it will update every row in the table. essentially the whole column.

26
Q

How do you delete rows from a database table?

A

delete from “products”
where “productId” = 24
returning *;

27
Q

How do you accidentally delete all rows from a table?

A

when no other keywords were not provided like delete from “products”; will delete the whole table rows

28
Q

What is a foreign key?

A

a column that specifically refers to values in a column of another table. is a constraint that one column has to match with another column

29
Q

How do you join two SQL tables?

A

FROM “table-name”

JOIN “table-name” USING (“column”)

30
Q

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

A

JOIN “table-name” AS “tn” USING (“column”);

31
Q

What are some examples of aggregate functions?

A

max(), avg(), count(), sum()
more on
https://www.postgresql.org/docs/current/functions-aggregate.html

aggravate bunch of values into one value, it returns one value. similar to join() in JS and reduce()

32
Q

What is the purpose of a group by clause?

A

The GROUP BY Clause is utilized in SQL with the SELECT statement to organize similar data into groups. It combines the multiple records in single or more columns using some functions.