我完全不知道这个create table语句的语法错误是什么。它是我正在创建的5个表中的一个,4个成功创建但是这个表失败
这是创建声明
//String to create a transaction table
private static final String CREATE_TRANSACTION_TABLE =
"CREATE TABLE " + Constants.TRANSACTION_TABLE + "("
+ Constants.COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ Constants.COLUMN_CUSTOMER_ID + " INTEGER, "
+ Constants.COLUMN_DATE_CREATED + " BIGINT, "
+ Constants.COLUMN_SUB_TOTAL_AMOUNT + " NUMERIC, "
+ Constants.COLUMN_LINE_ITEMS + " TEXT, "
+ Constants.COLUMN_TAX_AMOUNT + " NUMERIC, "
+ Constants.COLUMN_TOTAL_AMOUNT + " NUMERIC, "
+ Constants.COLUMN_LAST_UPDATED + " BIGINT, "
+ "FOREIGN KEY(customer_id) REFERENCES customer(_id)" + ")";
以下是突出显示错误的堆栈跟踪
08-24 19:13:25.376 10608-10608/com.okason.prontopos D/DatabaseHelper﹕ CREATE TABLE category(_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL, image_path TEXT, create_date BIGINT, last_update_date BIGINT )
08-24 19:13:25.376 10608-10608/com.okason.prontopos D/DatabaseHelper﹕ CREATE TABLE customer(_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL, email TEXT, phone TEXT, street1 TEXT, street2 TEXT, city TEXT, state TEXT, zip TEXT create_date BIGINT, last_update_date BIGINT, points NUMERIC )
08-24 19:13:25.376 10608-10608/com.okason.prontopos D/DatabaseHelper﹕ CREATE TABLE retailer(_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL, email TEXT, phone TEXT, street1 TEXT, street2 TEXT, city TEXT, state TEXT, zip TEXT, industry TEXT, create_date BIGINT, last_update_date BIGINT, manager_name TEXT )
08-24 19:13:25.376 10608-10608/com.okason.prontopos D/DatabaseHelper﹕ CREATE TABLE product(_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL, description TEXT, price NUMERIC, image_path TEXT, category_id INTEGER, create_date BIGINT, last_update_date BIGINT, FOREIGN KEY(category_id) REFERENCES category(_id))
08-24 19:13:25.380 10608-10608/com.okason.prontopos D/DatabaseHelper﹕ CREATE TABLE transaction(_id INTEGER PRIMARY KEY AUTOINCREMENT,customer_id INTEGER, create_date BIGINT, sub_total_amount NUMERIC, items TEXT, tax_amount NUMERIC, total_amount NUMERIC, last_update_date BIGINT, FOREIGN KEY(customer_id) REFERENCES customer(_id))
08-24 19:13:25.380 10608-10608/com.okason.prontopos E/SQLiteLog﹕ (1) near "transaction": syntax error
08-24 19:13:25.380 10608-10608/com.okason.prontopos E/DatabaseHelper﹕ near "transaction": syntax error (code 1): , while compiling: CREATE TABLE transaction(_id INTEGER PRIMARY KEY AUTOINCREMENT,customer_id INTEGER, create_date BIGINT, sub_total_amount NUMERIC, items TEXT, tax_amount NUMERIC, total_amount NUMERIC, last_update_date BIGINT, FOREIGN KEY(customer_id) REFERENCES customer(_id))null
答案 0 :(得分:3)
transaction
是SQL中的关键字。要将其用作标识符,您需要引用它,例如双引号为"transaction"
。或者只是将您的表重命名为例如transactions
使其成为非关键字标识符。