Hi All,

When I create a table and specify a unique constraint, a unique index is
automatically created. This index cannot be dropped, so the only way to get
rid of the uniqueness is to recreate the table without the constraint. No
problem.

When I create a table without the unique constraint, I can add the unique
requirement later by creating a unique index (if it works!). Apart from
behaving the same for INSERTS, this is not exactly the same because I can
simply drop the index to remove the unique requirement.

So my problem is, I need to know how the unique requirement was created in
the first place in order to get rid of it in the appropriate manner.

One solution would be to parse the SQL field in sqlite_master to look for
the constraint. (I'd prefer not!). I also don't really want to attempt a
DROP INDEX and then fall back to recreating the table since I am generating
scripts.

Another solution that ocurred to me is to check for "sqlite_autoindex_" in
the name field of pragma index_list(tablename). Can I simply assume that
unique indexes named sqlite_autoindex_* cannot be dropped?

Perhaps if pragma table_info(tablename) had a "unique" column like it has a
"notnull" column, but only for unique constraints on single fields. Or if
pragma index_list had a "constraint" (or "cantdrop" or something) column
that would indicate that the index cannot be dropped.

Am I missing something? How do you solve this problem?

Regards,

Paul.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to