in

System.Data.SQLite

An open-source, enhanced version of the SQLite database engine for Windows

Importance of the primary key

Last post 03-29-2008 11:45 PM by Wiaz. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-29-2008 3:07 PM

    Importance of the primary key

    Is the rowid in sqlite tables considered as a primary key to the table, or do I need to create another separate column to use as a primary key. 

    Thank you 

    Filed under: , ,
  • 03-29-2008 11:45 PM In reply to

    • Wiaz
    • Top 10 Contributor
    • Joined on 01-11-2007
    • Poland
    • Posts 46

    Re: Importance of the primary key

    if you dont specify column with 'integer primary key' then sqlite will do it as a internal priomary key named 'ROWID', but if you create column as a primary key then ROWID will be equal to this column.

    Please, read Sqlite docs!
    here you have cite from sqlite.org http://www.sqlite.org/lang_createtable.html

    Specifying a PRIMARY KEY normally just creates a UNIQUE index on the corresponding columns. However, if primary key is on a single column that has datatype INTEGER, then that column is used internally as the actual key of the B-Tree for the table. This means that the column may only hold unique integer values. (Except for this one case, SQLite ignores the datatype specification of columns and allows any kind of data to be put in a column regardless of its declared datatype.) If a table does not have an INTEGER PRIMARY KEY column, then the B-Tree key will be a automatically generated integer. The B-Tree key for a row can always be accessed using one of the special names "ROWID", "OID", or "_ROWID_". This is true regardless of whether or not there is an INTEGER PRIMARY KEY. An INTEGER PRIMARY KEY column can also include the keyword AUTOINCREMENT. The AUTOINCREMENT keyword modified the way that B-Tree keys are automatically generated. Additional detail on automatic B-Tree key generation is available separately ( http://www.sqlite.org/autoinc.html ).
    Wiaz
Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems