简体   繁体   English

创建 sqlite 数据库时使用“ ”的正确方法

[英]Correct way to use “ ” while creating sqlite database

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.例如,在“CREATE TABLE”中,“”放置在距 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.您只是要创建一个 SQL 查询。

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其中someTableName是表名,那么它将导致错误,因为它根本不是 SQL 查询

Note: you don't have to mention space after table If UtilConstants.KEY_NAME contains space at the beginning that also works...注意:您不必在表后提及空格如果UtilConstants.KEY_NAME在开头包含空格,也可以...

The SQL command would be CREATE TABLE [name] SQL 命令将是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您需要距离来产生空间,如果您不使用距离命令将是CREATE TABLE[name]它会将其检测为两个单词
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例如,您在String DATABASE_TABLE_CREATION中有一个StringDATABASE_TABLE_CREATION之间的空格,如果删除该空格,它将不起作用

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.这是因为如果您在这些关键字之后没有空格“”字符,例如TABLE ,sql 命令将理解您的关键字,例如TABLE[your_table_name] ,这不是有效的 SQL 术语。

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

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