如何在sqflite中的数据库中创建多个表? [英] How to create multiple tables in a database in sqflite?
问题描述
Im建筑物和使用SQLite数据库的应用程序出现波动。我使用这段代码创建了第一个表:
Im building and app with flutter that uses SQLite database. I have created first table using this piece of code:
void _createDb(Database db, int newVersion) async {
await db.execute('''CREATE TABLE cards (id_card INTEGER PRIMARY KEY,
color TEXT, type TEXT, rarity TEXT, name TEXT UNIQUE, goldCost INTEGER,
manaCost INTEGER, armor INTEGER, attack INTEGER, health INTEGER, description TEXT)''');
}
表已创建,我可以毫无问题地访问它。
Table gets created and I can access it without problems.
不幸的是,我不能包含刚刚创建的多个表。我尝试在同一方法中添加另一个SQL CREATE TABLE子句,然后在下一行中使用不同的SQL子句重复方法 db.execute
。
Unfortunately I cannot include more than 1 table that i just created. I tried adding another SQL CREATE TABLE clause in the same method, and repeating method db.execute
with a different SQL clause just in the next line.
我正在模仿本教程中的代码: https:// www。 youtube.com/watch?v=xke5_yGL0uk
I'm mimicing code from this tutorial: https://www.youtube.com/watch?v=xke5_yGL0uk
如何在同一数据库中添加另一个表?
How to add another table within the same database?
推荐答案
您可以将多个db.execute调用合并为示例
You can just combine multiple db.execute calls for exampple
await db.execute('''
create table $reminderTable (
$columnReminderId integer primary key autoincrement,
$columnReminderCarId integer not null,
$columnReminderName text not null,
$columnReminderNotifyMileage integer not null,
$columnReminderEndMileage integer not null
)''');
await db.execute('''
create table $carTable (
$columnCarId integer primary key autoincrement,
$columnCarTitle text not null
)''');
这篇关于如何在sqflite中的数据库中创建多个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!