Databases Flashcards

1
Q

How to join two databases together?

A

SELECT *
FROM student
JOIN enroll ON student.SID = enroll.SID

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

How to join three databases together?

A

SELECT *
FROM Investigation
JOIN Cases ON Cases.CID = Investigation.CID
JOIN Officers ON Officers.OID = Investigation.OID

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

What are the main features of SQLite?

A
  • Serverless
  • Zero configuration
  • Cross-platform
  • Small Runtime Footprint
  • Highly Reliable
  • Self-contained
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

SQLite syntax:
How to create database

A

sqlite3 <filename></filename>

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

SQLite syntax:
List names of tables

A

sqlite3 <filename><br></br>.tables</filename>

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

SQLite syntax:
Show structure of a table

A

sqlite3 <filename><br></br>.schema <table name>
</table></filename>

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

What import is needed for SQLite dbs?

A

import sqlite3

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

How to create a connection and run a query?

A

import sqlite3

conn = sqlite3.connect("dbfile.db")
curs = conn.cursor()
results = curs.execute("SELECT \* FROM table;")

for row in results:
print(row[0])

conn.close()

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

Create a table with Python

A

curs = conn.cursor()
curs.execute(“CREATE TABLE addressbook (\
ID INTEGER PRIMARY KEY AUTOINCREMENT,\
NAME TEXT);”)

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

How to split SQL on multiple lines?

A

result = cur.execute(“SELECT *\
FROM visits;”)

or

sql_query = “”” SELECT *
FROM visits
“”“

result = cur.execute(sql_query)

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

How to insert data into a table?

A

INSERT INTO lecturers VALUES (NULL,
‘Rian Bloggs’, ‘Dr’, ‘Head of School’,
’1990-12-10’);

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

How to update an entry in SQL?

A

UPDATE lecturers
SET Position=”Senior Lecturer’
WHERE Name=’Yves’;

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

How to delete an entry in SQL?

A

DELETE FROM lecturers
WHERE Name = ‘Yves’

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