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?
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 does not (as of this answer) support the alter table drop constraint
command. The allowed syntax can be seen here. 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;
Note that the insert into
could probably be simplified to not use explicit column names but I ve left it that way in case you want to change the structure as well.
For example, if you re removing the constraint on the parent_id
column, it s of dubious use to keep it there at all. In that case, you could modify the data transfer to:
CREATE TABLE child2 (id INTEGER PRIMARY KEY, description TEXT);
INSERT INTO child2 (id, description) SELECT id, description FROM CHILD;
I think this is an easier, more concise approach:
copy db.sqlite3 backup-db.sqlite3
echo .dump tablename | sqlite3 db.sqlite3 > modify.sql
(now delete or change the constraint in modify.sql)
echo drop table tablename; | sqlite3 db.sqlite3
sqlite3 db.sqlite3 < modify.sql
You can now redump the new database table and compare the differences.
With DB Browser for SQLite you can do this by going to Modify Table
then clicking on the constraints
tab, then clicking Remove constraint
.
I have values being cut off and would like to display the full values. Sqlite3 -column -header locations.dbs " select n.namelist, f.state, t.state from names n left join locations l on l.id = n.id ...
I ve had fine luck using SQLite with straight, direct SQL in Android, but this is the first time I m wrapping a DB in a ContentProvider. I keep getting a null pointer exception when calling ...
I got this error: OperationalError at / unable to open database file Things I ve tried so far are setting the absolute path of my dev.db file in the settings.py. I ve tried adding www-data to my ...
I am in the process of developing a desktop application that needs a database. The application is currently targeted to SQL Express 2005 and works wonderfully. However, I m not crazy about having ...
Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second! Background: We are using SQLite as part of a desktop ...
When we are using any gear enable site, and we go offline the gear automatically creating folder with /dbName#database ... assume 2 diff. website is there www.abc.com and www.xyz.com. when I go ...
How can I get metadata / constraints (primary key and "null allowed" in particular) for each column in a SQLite v2.8 table using PHP5 (like mysql_fetch_field for MySql)? sqlite_fetch_column_types (OO:...
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...