alter drop cockroach db contrain - constraints

ALTER TABLE public."users" DROP CONSTRAINT users_un;
error :
ERROR: unimplemented: cannot drop UNIQUE constraint "users_un" using ALTER TABLE DROP CONSTRAINT, use DROP INDEX CASCADE instead
Hint: You have attempted to use a feature that is not yet implemented.
See: https://go.crdb.dev/issue-v/42840/v21.1

You'll have to do DROP INDEX CASCADE on the index that corresponds to the constraint.
If you need the specific command, please provide the output to SHOW CREATE public.users.

Related

Literal (raw) value as foreign key in sqlite

is it possible to make something like this in sqlite ?
FOREIGN KEY(TypeCode, 'ARawValue', IdServeur) REFERENCES OTHERTABLE(TypeCode, TypeElem, IdServeur)
it says unknown column "ARawValue" in foreign key definition, is't there another way ?
No, this is not possible. A foreign key constraint must be defined only by columns in the child and parent tables.
Probably the next best solution is to add a column to the child table with a default value set to the literal value (and optionally a check constraint that restricts the column to that single value).
Strictly speaking, an sqlite unique partial index should have been a good alternative solution, but it did not work for me in testing on version 3.28.0. A partial index is an index defined with a WHERE clause and can even be marked as UNIQUE. The official foreign key documentation requires a UNIQUE index on the parent table. There is no explicit exclusion of partial indexes, so I thought it would be a good solution. I was able to create the index and even define the foreign key constraint on the partial index, but no matter what I tried I got a foreign key error upon INSERT into the child table, even when I had verified that the parent table contained a unique pair of values as defined by the index.

List check constraints of Teradata table

I need to get list of all check constraints related to given table. For example, if there table
create table table_with_check
( S_BYTEINT BYTEINT NOT NULL,
CONSTRAINT CHECK_CONSTR CHECK(S_BYTEINT > 10)
)
I have only full table name and I need a query that returns me name of check constraint("CHECK_CONSTR") and its expression(S_BYTEINT > 10). The only thing I've found is system table DBC.ConstraintName but there only check constraint name but not expression.
There's no system table named DBC.ConstraintName in Teradata.
There's a view dbc.Table_LevelConstraintsV, based DBC.TableConstraints, which contains info about table level constraints like your CHECK_CONSTR and named constraints on column level. If you got an unnamed column constraint it's found in dbc.ColumnsV.ColumnConstraint.

SQLite How to Combine the Check Constraints with Select Subquery on another table

As it said, I want to add a constraint to a table, and find cannot make Check and Select together.
Here is What I did:
Alter Table table2 Add Constraint chk_table2 Check(Colume21 IN (Select Colume11 From Table 1));
Why does it fail?
The documentation says:
The expression of a CHECK constraint may not contain a subquery.
In any case, you cannot use ALTER TABLE to add a constraint later.
However, your constraint looks like a foreign key, which is supported.

alter table drop column syntax error using sqlite

This is the schema of my table:
create table LPCG(ID integer primary key, PCG text, Desc text, test text);
I wish to drop the column "test", and hence use the command:
alter table LPCG drop column test;
This is the error message I get:
Error: near "drop": syntax error
Can someone please help me correct my error?
An additional question is: I understand that ID is the primary key attribute. Would I be able to drop that column? If not, is there a workaround which anyone has used?
Thanks in advance for any help.
Up to version 3.35, SQLite did not support ALTER TABLE DROP COLUMN statements. You could only rename table, or add columns.
If you want to drop a column, your best option was to create a new table without the column, and to drop the old table in order to rename the new one.
As of now, ALTER TABLE support is still limited but includes dropping a column, under conditions.

Innodb foreign key constraints

I am trying to change the type in two tables of an innoDB. The problem is that the values are a key and a foreign key. When I try to make the change I get the following error
#1025 error on rename
Do I need to drop the foreign keys and then make the changes and then reapply the foreign key?
Since u can use the name to drop the foreign key first and the column then:
ALTER TABLE categories DROP FOREIGN KEY categories_ibfk_1;
ALTER TABLE categories DROP COLUMN assets_id;
To find out which table caused the error you can run
SHOW ENGINE INNODB STATUS\G
and then look at the "LATEST FOREIGN KEY ERROR" section.
Yeah, you have to drop the foreign key. Try SHOW INNODB STATUS to see if there's a more elaborated explanation of what's going on.

Resources