0

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?

4
  • 3
    Why did you create 3 separate database files? If the tables are related, you need to store them in one database. Commented Apr 16, 2014 at 10:40
  • yh..i create 3 separate database files..how can i store them in one database? Commented Apr 16, 2014 at 10:48
  • 1
    Just open one database connection and create your tables in that one database? Commented Apr 16, 2014 at 10:48
  • thank you Martijn Pieters it's working Commented Apr 16, 2014 at 11:15

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

same in MySQL and other DBMS ?
@user3509090: same in any relational database.
@user3509090: cross-database foreign-key relationships are possible in some DBMS products but require extra work. It is not the norm, however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.