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)
-- projects table
CREATE TABLE IF NOT EXISTS projects (
id integer PRIMARY KEY,
name text NOT NULL,
begin_date text,
end_date text
);
-- tasks table
CREATE TABLE IF NOT EXISTS tasks (
id integer PRIMARY KEY,
name text NOT NULL,
priority integer,
project_id integer NOT NULL,
status_id integer NOT NULL,
begin_date text NOT NULL,
end_date text NOT NULL,
FOREIGN KEY (project_id) REFERENCES projects (id)
);
Code language: SQL (Structured Query Language) (sql)
import sqlite3
# it will create a databse with name sqlite.db
connection= sqlite3.connect('sqlite.db')