SQLite - Comments
The Comments are added in a SQLite statement with the purpose of making the statement easier to understand. It makes the SQLite statement more readable and hence easier to update it later. Comments are ignored when the statement is executed. In SQLite, there are two ways of putting a comment.
- Single line comment
- Multi-line comment
Consider a database table called Employee with the following records:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
Single line Comment
SQLite supports single line comment in two ways:
|
|
Example:
In the example below, two line comments are used. Comments are ignored when a statement is executed.
--first line comment # second line comment SELECT Name, Salary FROM Employee; -- third line comment
This will produce the result as shown below:
Name | Salary |
---|---|
John | 3000 |
Marry | 2750 |
Jo | 2800 |
Kim | 3100 |
Ramesh | 3000 |
Huang | 2800 |
Multi-line Comment
It starts with /* and ends with */. Anything between /* and */ is a block comment and will be ignored when the statement is executed.
Example:
In the below SQLite statement, multi-line comments are used. When this statement is executed these block of comments will be ignored.
/* comment line 1 comment line 2 */ SELECT EmpID, Name, City /* more comments */ FROM Employee;
This result of the above SQLite statement will be:
EmpID | Name | City |
---|---|---|
1 | John | London |
2 | Marry | New York |
3 | Jo | Paris |
4 | Kim | Amsterdam |
5 | Ramesh | New Delhi |
6 | Huang | Beijing |