import sqlite3
conn = sqlite3.connect('TestDB.db') # You can create a new database by changing the name within the quotes
c = conn.cursor() # The database will be saved in the location where your 'py' file is saved
# Create table - CLIENTS
c.execute('''CREATE TABLE CLIENTS
([generated_id] INTEGER PRIMARY KEY,[Client_Name] text, [Country_ID] integer, [Date] date)''')
# Create table - COUNTRY
c.execute('''CREATE TABLE COUNTRY
([generated_id] INTEGER PRIMARY KEY,[Country_ID] integer, [Country_Name] text)''')
# Create table - DAILY_STATUS
c.execute('''CREATE TABLE DAILY_STATUS
([Client_Name] text, [Country_Name] text, [Date] date)''')
conn.commit()
# Note that the syntax to create new tables should only be used once in the code (unless you dropped the table/s at the end of the code).
# The [generated_id] column is used to set an auto-increment ID for each record
# When creating a new table, you can add both the field names as well as the field formats (e.g., Text)
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
""" create a database connection to a SQLite database """
conn = None
try:
conn = sqlite3.connect(db_file)
print(sqlite3.version)
except Error as e:
print(e)
finally:
if conn:
conn.close()
if __name__ == '__main__':
create_connection(r"C:sqlitedbpythonsqlite.db")
Code language: Python (python)