-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateDB.py
More file actions
30 lines (25 loc) · 996 Bytes
/
createDB.py
File metadata and controls
30 lines (25 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Sqlite all ready come included with python
import sqlite3 # We import sqlite3
# Connect to database if existent or creates a new database if nonexistent
conn = sqlite3.connect("customers.db")
# Create a cursor
c = conn.cursor()
# Create a table
# In this case 'customers' is the name of the database / a database is LIKE a spreadsheet
# then you enter the name of variable in table and the datatype
c.execute("""CREATE TABLE customers (
first_name text,
last_name text,
email text
)""")
# Sqlite only has 5 datatype (although other databases like MySql have dozens more)
# SQLite DataTypes are:
# NULL (does it exist or doesnt),
# INTEGER (any whole number)
# REAL (any decimal number)
# TEXT (any text)
# BLOB (it is stored exactly like it is) (an image, mp3, etc. are some examples of blobs)
# 'Commits' (saves) the things we just made to the db (database)
conn.commit()
# Close connection to avoid mistakes & errors / it is a good practice to make it manually
conn.close()