I'm a newbie in Database. I'm trying to create some tables but it fails with error "near 'INDEX' : syntax error". Here is my codes to generate tables :
try {
using( SqliteCommand cmd = _db.CreateCommand() ) {
// create words table
cmd.CommandText = "DROP TABLE words";
cmd.ExecuteNonQuery();
cmd.CommandText =
"CREATE TABLE IF NOT EXISTS words(" +
"word_id INTEGER AUTO_INCREMENT," +
"word_eng VARCHAR(128)," +
"PRIMARY KEY(word_id)" +
")";
cmd.ExecuteNonQuery();
// create word_classes table
cmd.CommandText = "DROP TABLE word_classes";
cmd.ExecuteNonQuery();
cmd.CommandText =
"CREATE TABLE IF NOT EXISTS word_classes(" +
"word_class_id INTEGER," +
"word_class_name VARCHAR(50)," +
"PRIMARY KEY(word_class_id)" +
")";
cmd.ExecuteNonQuery();
// create meanings table
cmd.CommandText = "DROP TABLE meanings";
cmd.ExecuteNonQuery();
cmd.CommandText =
"CREATE TABLE IF NOT EXISTS meanings(" +
"meaning_id INTEGER AUTO_INCREMENT," +
"meaning VARCHAR(100)," +
"word_class_id INTEGER," +
"PRIMARY KEY(meaning_id)," +
"FOREIGN KEY(word_class_id) REFERENCES word_classes(word_class_id)" +
")";
cmd.ExecuteNonQuery();
// create word_meaning_realationship table
cmd.CommandText = "DROP TABLE word_meaning_realationship";
cmd.ExecuteNonQuery();
cmd.CommandText =
"CREATE TABLE IF NOT EXISTS word_meaning_realationship(" +
"word_id INTEGER," +
"meaning_id INTEGER," +
"FOREIGN KEY(word_id) REFERENCES words(word_id)" +
"FOREIGN KEY(meaning_id) REFERENCES meanings(meaning_id)" +
")";
cmd.ExecuteNonQuery();
// create decks table
cmd.CommandText = "DROP TABLE decks";
cmd.ExecuteNonQuery();
cmd.CommandText =
"CREATE TABLE IF NOT EXISTS decks(" +
"deck_id INTEGER AUTO_INCREMENT," +
"deck_name VARCHAR(128)," +
"deck_version INTEGER," +
"PRIMARY KEY(deck_id)" +
")";
cmd.ExecuteNonQuery();
// create deck_word_relationship table
cmd.CommandText = "DROP TABLE deck_word_relationship";
cmd.ExecuteNonQuery();
cmd.CommandText =
"CREATE TABLE IF NOT EXISTS deck_word_relationship(" +
"deck_id INTEGER," +
"word_id INTEGER," +
"FOREIGN KEY(deck_id) REFERENCES decks(deck_id)," +
"FOREIGN KEY(word_id) REFERENCES words(word_id)" +
")";
cmd.ExecuteNonQuery();
}
} catch( SqliteException ex ) {
Debug.LogError( "DBError : " + ex.ToString() );
}
It would be very appreciated if you check my other codes to create table, as I'm a totally newbie in database and mysql, and am not very confident of my codes :)
** updated ** I decided not to think about indexing for now. I updated my codes that have small errors that made my code not working. But if you tell me how to apply indexing for me, I will make it as a correct answer after application. Thanks for helps of you guys.
mysql?