Sqlite: adding comments to tables and columns?

前端 未结 3 1085
醉酒成梦
醉酒成梦 2021-02-05 01:38

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

Does Sqlite support adding comments to tables and columns?

相关标签:
3条回答
  • 2021-02-05 01:56

    When creating a table using sqlite (I'm using sqlite3 in python), the COMMENT section is not supported.

    This fails (works in full MySql syntax):

    CREATE TABLE `Info` (
      `Test` VARCHAR(512) NOT NULL COMMENT 'Column info here'
    );
    

    This works (no COMMENT in the column declaration):

    CREATE TABLE `Info` (
      `Test` VARCHAR(512) NOT NULL
    );
    
    0 讨论(0)
  • 2021-02-05 01:59

    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.

    0 讨论(0)
  • 2021-02-05 02:13

    (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;
    
    0 讨论(0)
提交回复
热议问题