error while trying to alter a column in a table - sql

I am trying to alter the size of a column 'Login' which is a primary key in my table 'Utilisateurs' which is in my in 'ME' database. I tried this command:
ALTER TABLE ME.UTILISATEURS
ALTER COLUMN login VARCHAR (50) ;
but I get this error:
Error code -1, SQL state 42X01: syntax Erreur : Encountered "varchar" at line 2, column 21.
I am using netbeans IDE, the Derby Driver.

ALTER TABLE ME.UTILISATEURS
ALTER COLUMN login SET DATA TYPE VARCHAR(50)

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

Error when loading table from MSSQL Server to Informix DB

I am trying to load a table from MSSQL - IBM Informix DB. Tables without Primary key are getting loaded but ones with Primary key are not loading and throwing following error
Stream component 'st_2_Informix_Target' terminated
Stream component failed at subtask 2, component st_2_Informix_Target
Error executing data handler
Handling new table 'dbo'.'region3' failed
execute create primary key failed, statement ALTER TABLE dbo.region3 ADD CONSTRAINT region3_PK__region3__3213E83F82CE48A3 PRIMARY KEY ( id )
RetCode: SQL_ERROR SqlState: 42000 NativeError: -201 Message: [Informix][Informix ODBC Driver][Informix]A syntax error has occurred.
Failed (retcode -1) to execute statement: 'ALTER TABLE dbo.region3 ADD CONSTRAINT region3_PK__region3__3213E83F82CE48A3 PRIMARY KEY ( id )'
Someone (I guess SQLServer or DMS) is trying to add a primary key to the Informix table using SQLServer SQL syntax which is not valid in Informix.
> ALTER TABLE dbo.region3 ADD CONSTRAINT region3_PK__region3__3213E83F82CE48A3 PRIMARY KEY ( id );
201: A syntax error has occurred.
Error in line 1
Near character position 40
> ALTER TABLE dbo.region3 ADD CONSTRAINT PRIMARY KEY ( id ) CONSTRAINT region3_PK__region3__3213E83F82CE48A3;
Table altered.
>
I suggest to check if there are any options to disable PK creation when doing the load task.

Can't ALTER COLUMN TYPE in PostgreSQL "0A000: Cannot alter column "FIELDA" of relation "TABLEA"

Trying to run the below script:
ALTER TABLE SCHEMA.TABLEA
ALTER COLUMN FIELDA TYPE VARCHAR(5)
And I am getting the following error:
0A000: Cannot alter column "FIELDA" of relation "TABLE"
The field is currently an integer and contains no data, only nulls.
As per the AWS documentation you cannot change the data type of a VARCHAR only the size.
https://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_TABLE.html

Cannot Alter Column in Squirell SQL Client

I am trying to alter a column in my ingres DB to expand the size of the column.
The query i'm running is
ALTER TABLE test_table ALTER COLUMN address varchar(100) NOT NULL
Which gives error
Error: ALTER TABLE: invalid change of attributes on an ALTER COLUMN
SQLState: 42000 ErrorCode: 3859
Anyone any idea why I'm getting this error? I've checked the syntax for altering tables.
Probably you have NULL in data. Update your table first (set to empty string or any value you want):
LiveDemo
UPDATE test_table
SET address = '' -- or another value indicating missing addres like 'none'
WHERE address IS NULL;
And then try:
ALTER TABLE test_table ALTER COLUMN address varchar(100) NOT NULL;
EDIT:
If you don't want to enforce NOT NULL use just:
LiveDemo2
ALTER TABLE test_table ALTER COLUMN address varchar(100);

sql server modify error

i m not able to modify table in SQL server. i m new to databases.
use work
go
alter table employee
modify id varchar(20)
error message is-
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'modify'
here is an screenshot
thanks
You have the syntax for altering a table wrong. You need:
ALTER TABLE YourTable
ALTER COLUMN ExistingColumn VARCHAR(20)
The syntax should be
ALTER TABLE Employee ALTER COLUMN ID VarChar (20)
Here is the ALTER COLUMN syntax.
http://msdn.microsoft.com/en-us/library/ms190273.aspx
Now, having said all that, I have a question for you.. Why is your ID column a VarChar as opposed to an Identity Column?