views:

93

answers:

1

I have the following table:

CREATE TABLE child( 
  id INTEGER PRIMARY KEY, 
  parent_id INTEGER CONSTRAINT parent_id REFERENCES parent(id), 
  description TEXT);

How do I drop the constraint?

sqlite> ... ?

+1  A: 

SQLite does not support the alter table drop constraint command. You will need to create a new table without a constraint, transfer the data, then delete the old table.

I think something like the following should work:

CREATE TABLE child2 ( 
    id INTEGER PRIMARY KEY, 
    parent_id INTEGER,
    description TEXT
);
INSERT INTO child2 (id, parent_id, description)
   SELECT id, parent_id, description FROM CHILD;
DROP TABLE child;
ALTER TABLE child2 RENAME TO child;

You could also leave out parent_id from all the statements above if you don't want it transferred.

paxdiablo
Sad face. This is what I figured. I hoped I was misunderstanding the 'ommitted' doc.
TheDeeno