ORA-01735: invalid ALTER TABLE option - sql

alter table bu_consultas drop constraint if exists fk_b_cnslts_cdg_sr_d;
Error SQL: ORA-01735: invalid ALTER TABLE option

There is no IF EXISTS clause in the ALTER TABLE command for Oracle. If the constraint doesn't exist the command will fail, but no harm done.

Related

Error in changing column length in Postgres

I am trying to change the column size from 100 to 150 varchar data type using following query:
alter table data_warehouse.tbl_abc
alter column first_nm varchar(150) null;
Getting the following error:
SQL Error [42601]: ERROR: syntax error at or near "varchar"
Position: 77
The syntax is a bit different, so try this:
ALTER TABLE data_warehouse.tbl_abc
ALTER COLUMN first_nm type varchar(120);
The error in your syntax is that you missed a TYPE keyword:
ALTER TABLE data_warehouse.tbl_abc
ALTER COLUMN first_nm TYPE varchar(150);
and if you have a NOT NULL constraint you want to remove, add a new ALTER COLUMN inside the same ALTER TABLE statement:
ALTER TABLE data_warehouse.tbl_abc
ALTER COLUMN first_nm TYPE varchar(150),
ALTER COLUMN first_nm DROP NOT NULL;
for reference look here: https://www.postgresql.org/docs/current/sql-altertable.html
Edit: as in the comment, if you have a view which involves the same column, drop it and re-create it under transaction:
BEGIN TRANSACTION;
DROP VIEW [...];
ALTER TABLE [...];
CREATE VIEW [...];
COMMIT;
Be aware that to alter a table, you must acquire an exclusive lock on it, so during the whole process, all the queries over the same table and on the views of the table are locked, also if they don't read from the altered column (because the whole table is locked) - use with caution in production environment

Drop WITH CHECK CONSTRAINT or a function in MSSQL

I have altered a existing table using the following query
ALTER TABLE CodeAccess
WITH CHECK ADD CONSTRAINT CK_CodeAccess_Code
CHECK (dbo.chkCodeList('text1', 'text2', [Codes]) = 'True')
Now, I want to drop the function chkCodeList(, ,) from CodeAccess table. I have tried using
IF EXISTS (
SELECT * FROM sysobjects WHERE id = object_id(N'dbo.chkCodeList')
AND xtype IN (N'FN', N'IF', N'TF')
)
DROP FUNCTION dbo.chkCodeList
GO
It gives following error
Cannot DROP FUNCTION 'dbo.chkCodeList' because it is being referenced by object 'CK_CodeAccess_Code'.
So, executing...
ALTER TABLE CodeAccess NOCHECK CONSTRAINT CK_CodeAccess_Code
Command(s) completed successfully.
Now, I am trying alter the table using the first query and it gives me...
There is already an object named 'CK_CodeAccess_Code' in the database.
and executing second query, I got same error message...
Cannot DROP FUNCTION 'dbo.chkCodeList' because it is being referenced by object 'CK_CodeAccess_Code'.
I also tried without prefix dbo
So, How can i remove the function chkCodeList()?
Try dropping the constraint instead of NOCHECK. That is, drop the constraint -> drop the function like
ALTER TABLE CodeAccess
DROP CONSTRAINT CK_CodeAccess_Code;
DROP FUNCTION dbo.chkCodeList;
In your case, you are setting NOCHECK but the constraint still exists and so, when you try running the ALTER command again it says object named 'CK_CodeAccess_Code' already exists.

Drop "not null" Constraint Error in Oracle 11g

I'm using the following code in Oracle 11g
alter table account_creation
drop constraint branch_code;
I get an error saying cannot drop constraint non existent constraint but when I check the table the NULL constraint still exists for that particular column
Am I using the correct syntax?
Use this syntax:
ALTER TABLE account_creation
MODIFY (branch_code varchar(10) NULL);

Can't ALTER TABLE in ACCESS 2012

I'm trying to alter the table of an access database. I keep getting a syntax error for something I think should be pretty simple.
Here is what I tried to do and the error I am getting.
yes you have syntax error as what access tells you, try this one
ALTER TABLE EMP_2 ADD COLUMN EMP_PCT NUMBER(4);
ALTER TABLE EMP_2 ADD COLUMN PROJ_NUM CHAR(3);
the syntax
ALTER TABLE table {ADD {COLUMN field type[(size)] [NOT NULL] [CONSTRAINT index] |
ALTER COLUMN field type[(size)] |
CONSTRAINT multifieldindex} |
DROP {COLUMN field I CONSTRAINT indexname}}
ALTER TABLE statement

Why does this 'modify table' statement fail?

I'm trying to add a 'not null' constraint to a column in Oracle 9.
ALTER TABLE user_roles modify group_id varchar2(36 char) set not null;
However, the operation fails with an odd error:
Error report:
SQL Error: ORA-12987: cannot combine drop column with other operations
12987. 00000 - "cannot combine drop column with other operations"
*Cause: An attempt was made to combine drop column with other
ALTER TABLE operations.
*Action: Ensure that drop column is the sole operation specified in
ALTER TABLE.
Any ideas why this is failing?
Remove set:
ALTER TABLE user_roles modify group_id varchar2(36 char) not null
And yes, Oracle's errors can be very misleading.
It turns out the syntax of the above statement is wrong. It should be:
ALTER TABLE user_roles modify group_id varchar2(36 char) not null;
Still, the presence of an erroneous 'set' leads to a very odd error!
I'm trying to add a 'not null'
constraint to a column in Oracle 9.
If you are really trying jsut to make the column NOT NULL (i.e. you don't want to change the datatype at the same time) you just need to
ALTER TABLE user_roles modify not null;