I am confused about why at some places it is necessary to place " " at some distance from the text. For Eg In "CREATE TABLE ", the " is placed at some distance from TABLE.
String DATABASE_TABLE_CREATION = "CREATE TABLE "+ UtilConstants.TABLE_NAME+"(" + UtilConstants.KEY_ID
+ " Integer PRIMARY KEY," + UtilConstants.KEY_NAME + " TEXT," +
UtilConstants.KEY_PHONENUMBER + "TEXT" + ")";
db.execSQL(DATABASE_TABLE_CREATION);
Basically by writing this code
String DATABASE_TABLE_CREATION = "CREATE TABLE "+ UtilConstants.TABLE_NAME+"(" + UtilConstants.KEY_ID
+ " Integer PRIMARY KEY," + UtilConstants.KEY_NAME + " TEXT," +
UtilConstants.KEY_PHONENUMBER + "TEXT" + ")";
db.execSQL(DATABASE_TABLE_CREATION);
you are just going to create a SQL query.
Now imagine if you don't put a space after table the query will be something like this
CREATE TABLEsomeTableName ......
where someTableName is table name then it will cause an error because it is not a SQL query at all
Note: you don't have to mention space after table If UtilConstants.KEY_NAME contains space at the beginning that also works...
The SQL command would be CREATE TABLE [name]
You need the distance to produce the space, if you would not use the distance the command would be CREATE TABLE[name]
it would detect it as two words
For example, you have in String DATABASE_TABLE_CREATION
a space between String
and DATABASE_TABLE_CREATION
it would not work if you remove the space
Its because if you don't have the space " " character after these keyword like TABLE
, the sql command will understand your keyword like TABLE[your_table_name]
and that is not a valid SQL term.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.