Reputation: 9390
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!
Upvotes: 1
Views: 2746
Reputation: 1
Relative novice when it comes to SQLite but I suspect the issue is due to the existence of ROWID, although I can't comprehend why that would be an insurmountable problem. As to why one would want to add a primary key to an existing table, think about adding a huge amount of data to a table. Insert, sort index (indices), insert, sort, ... vs. insert, insert, ..., insert, sort. Depending on the amount of data, the inserts could take seconds, the index sorts, hours.
Upvotes: 0
Reputation: 290
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
Upvotes: 1