简体   繁体   English

创建表时出现主键声明错误

[英]primary key declaration error while creating table

CreateL()
{
_LIT(KSQLCountry, "CREATE TABLE Country(CountryID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,CountryName VARCHAR(45) NOT NULL,CountryCode VARCHAR(10) NOT NULL)");
User::LeaveIfError(iDatabase.Execute(KSQLCountry));
}

while creating table i want to declare for primary key and foreign key 创建表时,我想声明主键和外键

which showing run time error (it crashes) during creation of table 在创建表期间显示运行时错误(崩溃)

what is right way to declare primary key 什么是声明主键的正确方法

I don't know which DB are you using, but maybe this will help you 我不知道您使用的是哪个数据库,但这也许会对您有所帮助

http://snippets.dzone.com/posts/show/1680 http://snippets.dzone.com/posts/show/1680

Try to use COUNTER data type instead of INTEGER and AUTOINCREMENT. 尝试使用COUNTER数据类型代替INTEGER和AUTOINCREMENT。

Another guess: isn't that AUTO_INCREMENT with underscore? 另一个猜测:下划线不是AUTO_INCREMENT吗?

AUTO_INCREMENT确实带有下划线,这是该SQL中的错误

Seems like you're using the old legacy Symbian DBMS and not SQLite. 似乎您使用的是旧版Symbian DBMS,而不是SQLite。

The old DBMS only supports a small subset of SQL. 旧的DBMS仅支持一小部分SQL。 If my memory serves me well, that includes only some basic SELECT queries. 如果我的记忆很好,那就只包括一些基本的SELECT查询。

To create tables using the old DBMS, use the C++ API, eg 要使用旧的DBMS创建表,请使用C ++ API,例如

CDbColSet* columns = CDbColSet::NewLC();

TDbCol id(_L("CountryID"), EDbColInt32);
id.iAttributes = TDbCol::EAutoIncrement | TDbCol::ENotNull;
columns->AddL(id);               

columns->AddL(TDbCol(_L("CountryName"), EDbColText, 45));
columns->AddL(TDbCol(_L("CountryCode"), EDbColText, 10));

User::LeaveIfError(aDatabase.CreateTable(_L("Country"), *columns));

CleanupStack::PopAndDestroy(columns);

Or just use the more recent SQLite-backed RSqlDatabase API. 或者只使用更新的SQLite支持的RSqlDatabase API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM