gpt4 book ai didi

iphone - iPhone sdk中的sqlite外键

转载 作者:行者123 更新时间:2023-12-03 20:57:26 25 4
gpt4 key购买 nike

大家好, 我计划创建一个 TableView 和相应行的详细 View ,所有数据都从 sqlite 数据库中获取。为此,我在数据库中创建了两个表,第一个表用于 TableView 列表中的数据,第二个表用于表列表的详细 View 。我将产品 ID 设置为表一的主键。我想要产品 ID 作为表二的外键。我不知道如何为其设置外键,也不知道如何从表二中检索并将其显示在详细 View 中。请帮助我做到这一点。提前致谢...

最佳答案

 1.Change your DB Settings enable to Foreign Keys.

2.Create the child table like this


table1 is the parent table having id1 as primary key.

CREATE TABLE "table1" ("id1" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)

table2 is the child table having id2 as a foreign key with reference to id1 of table1.

CREATE TABLE table2 (
id2 INTEGER,
parent_id INTEGER,
description TEXT,
FOREIGN KEY (id2) REFERENCES table1(id1)
)

使用等值连接从表中检索数据。

 select * from table1,table2 where table1.id1=table2.id2;

or

select table2.* from table2,table1 where table1.id1=table2.id2;

to retrieve the data from single table alone.

希望这对您有帮助!

关于iphone - iPhone sdk中的sqlite外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4039865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com