Search code examples
iphonesqlite

How to add Primary Key from Existing table in SQLite?


Now i am working in SQLite database. I want to add primary key from my existing table. But i couldn't add the primary key in existing table and i have deleted all the records in the old table. So how can i add the primary key from existing table in SQLite?

Here my query is,

        alter table studetails add constraint pk primary key (rollno).

I have used that above query, but it shown error. Is it possible?, if yes, please guide me.

Thanks!


Solution

  • you cannot according to SQLite's syntax perform this operation. In general it seems strange to add a primary key to an existing table. This should be done using the create table statement (you can also add an index by create index).

    Br Anders

    Alter table in SQLite
    Create table in SQLite