SQL Basics + Manipulation Flashcards

1
Q

define table

A

collection of data organized into rows and columns.

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

relation

A

another word for a table: collection of data organized into rows and columns.

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

define column

A

a set of data values of a particular type

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

define row

A

A row is a single record in a table.

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

“*” character

A

Wildcard character. It allows you to select every column in a table without having to name each one individually.

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

most common data types (4)

A

INTEGER, a positive or negative whole number
TEXT, a text string
DATE, the date formatted as YYYY-MM-DD
REAL, a decimal value

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

define statement

A

text that the database recognizes as a valid command.

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

what do statements end with?

A

SEMICOLON ;

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

What does the SELECT statement return?

A

a new table called the result set.

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

3 components of a statement

A

1) Clause/Command: performs a specific task
2) Table Name
3) Parameter: list of columns, data types, or values passed to a clause as an argument

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

CREATE statements

A

allow us to create a new table in the database

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

SELECT statements

A

fetch data from a database

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

INSERT statement

A

inserts a new row into a table.

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

ALTER TABLE statement

A

add, delete, or modify columns in an existing table.

also used to add and drop various constraints on an existing table.

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

ADD COLUMN statement

A

lets you add a column to the table

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

syntax for adding a column

A

ALTER TABLE [talename]
ADD COLUMN [columnname] COLUMN DATA TYPE;

17
Q

what is NULL?

A

Represents missing or unknown data

18
Q

can you add a column at a specific position to a table?

A

No. by default a new column will always be added to the end of the table.

BUT you can always select columns in any order eg SELECT col3, col5, col2;

an alternative is to reate a new table and add columns in your preferred order.

19
Q

UPDATE statement

A

edits a row in a table.

20
Q

SET command

A

indicates the column to edit, takes the =

21
Q

WHERE command

A

indicates which row(s) to update with the new column value

22
Q

how is ALTER different from UPDATE?

A

ALTER modifies columns. Can add, delete, or modify.

UPDATE modifies rows. Can only change them, not add or remove.

23
Q

UPDATE syntax

A

UPDATE table name
SET column name = new data
WHERE row name = row specifier

24
Q

DELETE FROM statement

A

deletes one or more existing rows from a table

25
Q

DELETE FROM syntax

A

DELETE FROM table name
WHERE row or rows IS or = PARAMETERS

26
Q

how do we delete a specific number of rows? what is the syntax?

A

using the LIMIT statement: syntax:

DELETE FROM tablename
WHERE condition
LIMIT x

where x is the number of items you want to delete

27
Q

define constraint

A

add information about how a column can be used

28
Q

at what point during the command do we invoke constraints? How do we separate constraints?

A

after specifying the data type for a column

separated by a comma ,

29
Q

what is a PRIMARY KEY column

A

used to uniquely identify the row. Attempts to insert a row with an identical value to a row already in the table will result in a constraint violation

30
Q

UNIQUE columns

A

must have a different value for every row. similar to PRIMARY KEY except a table can have many different UNIQUE columns

31
Q

NOT NULL columns

A

require a value to be present, otherwise constraint violation

32
Q

DEFAULT columns

A

take an additional argument that will be the assumed value for a new row if the user does not specify a value for that column.

33
Q

what are 3 reasons we might want to apply constraints to a table?

A
  • preventing invalid data and therefore incorrect calculations
  • prevent missing data
  • uniqueness
34
Q

DROP TABLE command

A

permanently removes a table from a database. not frequently used

35
Q

ANALYZE command

A

obtains statistics about a table

36
Q

what is SQLite and what distinguishes it from others of its kind?

A

it’s a database engine – software that allows users to interact with a relational database

a database is stored in a single file, which makes copying and sharing databases very easy

37
Q

what are drawbacks to sqlite?

A

1 only one user can update the file at a time
2 security requires more work
3 advanced features are limited
4 creates schemas, but doesn’t enforce them - doesn’t validate data types - any data type can be stored in any column