[英]How to use SQLite SELECT query in python
I have created 3 tables like the following 我已经创建了3个如下表
----------------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? 如果我使用python在这些表之间建立关系并执行“ SELECT”查询,如何为该任务连接这3个表?
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? 因此,我可以连接
chiledata.sqlite
但是如何连接其他两个数据库表( dogdata.sqlite
, dogChilddata.sqlite
)以执行SELECT
查询呢?
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.
连接到它,仅使用该一个连接创建表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.