0% found this document useful (0 votes)
2 views1 page

SQLite To-Do List Database Setup

The document contains a Python script that creates a SQLite database named 'todo_list.db'. It defines tables for Users, Tags, UserDetails, Tasks, and a many-to-many relationship table Tasks_Tags, with appropriate foreign key constraints. The script ensures that the database is set up correctly when executed.

Uploaded by

gaithslman2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

SQLite To-Do List Database Setup

The document contains a Python script that creates a SQLite database named 'todo_list.db'. It defines tables for Users, Tags, UserDetails, Tasks, and a many-to-many relationship table Tasks_Tags, with appropriate foreign key constraints. The script ensures that the database is set up correctly when executed.

Uploaded by

gaithslman2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import sqlite3

def create_db():
conn = [Link]('todo_list.db')
[Link]('pragma foreign_keys = ON')

#TABLES CREATION SCRIPTS

[Link]('''CREATE TABLE IF NOT EXISTS Users(


user_id INTEGER PRIMARY KEY,
name TEXT,
email TEXT
)''')
[Link]('''CREATE TABLE IF NOT EXISTS Tags(
tag_id INTEGER PRIMARY KEY,
name TEXT
)''')
[Link]('''CREATE TABLE IF NOT EXISTS UserDetails(
user_details_id INTEGER PRIMARY KEY,
user_id INTEGER,
phone_number TEXT,
preferences TEXT,
address TEXT,
FOREIGN KEY(user_id) REFERENCES Users(user_id)
)''')
[Link]('''CREATE TABLE IF NOT EXISTS Tasks(
task_id INTEGER PRIMARY KEY,
user_id INTEGER,
description TEXT,
due_date DATE,
status TEXT,
FOREIGN KEY(user_id) REFERENCES Users(user_id)
)''')
[Link]('''CREATE TABLE IF NOT EXISTS Tasks_Tags(
task_id INTEGER,
tag_id INTEGER,
FOREIGN KEY(task_id) REFERENCES Tasks(task_id),
FOREIGN KEY(tag_id) REFERENCES Tags(tag_id),
PRIMARY KEY(task_id, tag_id)

)''')
[Link]()
[Link]()
if __name__ == "__main__":
create_db()

You might also like