How can I determine in a table already exists before I start adding data to it again, in as few lines of code as possible?
Asked
Active
Viewed 4,306 times
2 Answers
4
If you are using sqlite directly, you can use the following query to see if the table already exists:
SELECT name FROM sqlite_master WHERE type='table' AND name='my_table_name';

Codebeef
- 43,508
- 23
- 86
- 119
-
Yeah I've seen that just wondered if there was a quicker way or an inbuilt function ? – Jules Sep 29 '10 at 09:46
4
sqlite3_stmt *statementChk;
sqlite3_prepare_v2(database, "SELECT name FROM sqlite_master WHERE type='table' AND name='util_nums';", -1, &statementChk, nil);
bool boo = FALSE;
if (sqlite3_step(statementChk) == SQLITE_ROW) {
boo = TRUE;
}
sqlite3_finalize(statementChkUN);

Jules
- 7,568
- 14
- 102
- 186