Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite: adding COMMENT ON descriptions to tables and columns?

In MySQL Workbench you can add COMMENTs to tables and columns in a MySQL database.

Does Sqlite support adding comments to tables and columns?

like image 736
warvariuc Avatar asked Sep 15 '11 05:09

warvariuc


People also ask

How do I comment in SQLite?

In SQLite, a comment that starts with /* symbol and ends with */ and can be anywhere in your SQL statement. This method of commenting can span several lines within your SQL.

How do you add a comment to a column in SQL?

Use the COMMENT statement to add a comment about a table, view, materialized view, or column into the data dictionary. To drop a comment from the database, set it to the empty string ' '. See Also: "Comments" for more information on associating comments with SQL statements and schema objects.


2 Answers

I don't think it does. The "SQL As Understood By SQLite" page makes no mention of table or column comments nor does the CREATE TABLE or ALTER TABLE documentation.

Also, the Unsupported SQL wiki page has this:

2009-08-04: Table and column comments - I have scoured the doco and can't find anything about applying comments to tables or their columns.

Yes, that's a wiki page from 2009 but that note is supported by the rest of the documentation.

However, SQLite does preserve SQL comments that you put in your DDL. If you feed this to the sqlite3 CLI tool:

CREATE TABLE User         -- A table comment (         uid INTEGER,    -- A field comment         flags INTEGER   -- Another field comment ); 

Then you get exactly that back from a .schema command:

sqlite> .schema CREATE TABLE User         -- A table comment (         uid INTEGER,    -- A field comment         flags INTEGER   -- Another field comment ); 

So you should be able to fake it if you can control the DDL used to create your tables.

like image 65
mu is too short Avatar answered Oct 07 '22 10:10

mu is too short


(This isn't what the original poster was asking, but this is what I was looking for when I first found this question based on the keywords in the title.)

How to make comments in SQLite

There are two ways to make comments in SQLite code:

Hyphens

-- this is my comment SELECT * FROM employees; 

C-style

/* this is my comment */  SELECT * FROM employees; 
like image 34
Suragch Avatar answered Oct 07 '22 08:10

Suragch