SQL Flashcards

1
Q

how do I create a database

A

sqlite3 title.db or CREATE DATABASE title;

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

how do I create a table

A

CREATE TABLE title (
column1 data type constraints,
column2 data type constraints,
etc.);

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

how do I delete a table

A

DROP TABLE title;

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

how do I put data in a table

A

INSERT INTO title (column, column, etc) VALUES (value, value, etc);

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

how do I view a table

A

SELECT * FROM title;

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

how do I view certain columns of a table

A

SELECT column, column, etc FROM table;

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

how do I filter out the rows in a selection

A

SELECT column, column etc FROM table WHERE constraint;

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

How do I change data once in a table already

A

UPDATE table SET column = new value WHERE constraint;

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

how do I delete rows

A

DELETE FROM table WHERE constraint;

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

How do I add a column to a table

A

ALTER TABLE table ADD new column;

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

How do I delete a column in a table

A

ALTER TABLE table DROP column;

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

How do I rename a column in a table

A

ALTER TABLE table RENAME column TO new name;

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

How do I clear all data from a table

A

TRUNCATE TABLE table;

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

What are some common constraints when creating columns in a table

A

NOT NULL means it needs to be given a value, UNIQUE means it can not have the same value as another row, DEFAULT allows you to set a default value if left empty, AUTO_INCREMENT will increase the id each time a row is created

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

How can we do more complicated constraints on columns

A

can use CONSTRAINT label of constraint CHECK (set of constraints with logical connectives), or something like CONSTRAINT label of constraint UNIQUE(column, column) to make sure no two rows have the same values in both those columns

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