user3509090
user3509090

Reputation: 49

How to use SQLite SELECT query in python

I have created 3 tables like the following

----------------Database name is chiledata.sqlite---------------

CREATE TABLE child (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT
);
----------------Database name is dogdata.sqlite---------------

CREATE TABLE dog (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    dog TEXT
);
----------------Database name is dogChilddata.sqlite---------------

CREATE TABLE child_dog {
    child_id INTEGER,
    dog_id INTEGER,
    FOREIGN KEY(child_id) REFERENCES child(id),
    FOREIGN KEY(dog_id) REFERENCES dog(id)
};

If I use python for make relationship between these tables and execute "SELECT" query how can I connect these 3 tables for this task?

ex:

#Import the sqlite3 module
import sqlite3
# Create a connection and cursor to your database
conn = sqlite3.connect('chiledata.sqlite')
c = conn.cursor() 

So I can connect chiledata.sqlite but how can I connect other two database tables (dogdata.sqlite, dogChilddata.sqlite) to execute SELECT query?

Upvotes: 0

Views: 152

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121216

Don't use separate database files if your tables are supposed to be related.

Store all your tables in one database file; connect to it, create the tables with that one connection only.

Upvotes: 1

Related Questions