Error when loading table from MSSQL Server to Informix DB - sql

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.

Related

SQL Informix - adding foreign key

I am struggling while creating new database tables with foreign keys in Informix DB.
I need to migrate from one database to another. I am using DBeaver as DB browsing and editing tool. I am trying to run script like this (I just changed names). The commands come from DBeaver DDL export itself, so this is how it should be.
DROP TABLE IF EXISTS eapp:test_table1;
CREATE TABLE eapp:test_table1 (
column1 smallint NOT NULL,
PRIMARY KEY (column1) CONSTRAINT table1_pk
);
DROP TABLE IF EXISTS eapp:test_table2;
CREATE TABLE eapp:test_table2 (
column1 smallint NOT NULL,
column2 varchar(100) NOT NULL,
column3 smallint NOT NULL,
column4 smallint,
PRIMARY KEY (column1) CONSTRAINT table2_pk,
FOREIGN KEY (column4) REFERENCES eapp:test_table1(column1) ON DELETE RESTRICT ON UPDATE RESTRICT CONSTRAINT table2_fk
);
However, execution keeps crashing with a weird trimmed error message:
The language is Czech and it says something like "Syntax error. (Important notice: Database servers, that". But the rest is trimmed even in detail, so I have no idea what is going on.
Full stack:
org.jkiss.dbeaver.model.sql.DBSQLException: SQL Error [42000]: Chyba syntaxe. (Důležitá poznámka: Databázové servery, které
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:134)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeStatement(SQLQueryJob.java:473)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.lambda$0(SQLQueryJob.java:412)
at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:148)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeSingleQuery(SQLQueryJob.java:405)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.extractData(SQLQueryJob.java:865)
at org.jkiss.dbeaver.ui.editors.sql.SQLEditor$QueryResultsContainer.readData(SQLEditor.java:2833)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.lambda$0(ResultSetJobDataRead.java:98)
at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:148)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.run(ResultSetJobDataRead.java:96)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer$17.run(ResultSetViewer.java:3356)
at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:103)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.sql.SQLException: Chyba syntaxe. (Důležitá poznámka: Databázové servery, které
at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:413)
at com.informix.jdbc.IfxSqli.a(IfxSqli.java:3537)
at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3853)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2653)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2569)
at com.informix.jdbc.IfxSqli.executeExecute(IfxSqli.java:2446)
at com.informix.jdbc.IfxSqli.executeExecute(IfxSqli.java:2421)
at com.informix.jdbc.IfxResultSet.b(IfxResultSet.java:393)
at com.informix.jdbc.IfxStatement.a(IfxStatement.java:1326)
at com.informix.jdbc.IfxStatement.executeImpl(IfxStatement.java:1296)
at com.informix.jdbc.IfxStatement.c(IfxStatement.java:1007)
at com.informix.jdbc.IfxStatement.execute(IfxStatement.java:893)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.execute(JDBCStatementImpl.java:338)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:131)
... 12 more
Caused by: java.sql.SQLException
at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:413)
at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3858)
... 23 more
I was unable to Google message like that, so I am trying to ask here, if anyone has some experience with Informix DB and could possibly give me some hints.
I already tried to remove FK declaration from table creation and add it afterwards via ALTER TABLE, but it yields the same...
DBeaver is not generating valid Informix DDL. Informix does not understand ON DELETE RESTRICT ON UPDATE RESTRICT syntax.
From the online manual:
REFERENCES Clause
|--REFERENCES--table--+------------------+---------------------->
| .-,------. |
| V | |
'-(----column-+--)-'
>--+-------------------------+----------------------------------|
| (1) |
'-------ON DELETE CASCADE-'

How to link a sequence to a field with PostgreSQL?

In documentation of postgreSQL 9.6, it said to have serial equivalent we have to link the sequence to the field.
https://www.postgresql.org/docs/9.6/datatype-numeric.html (¤ 8.1.4)
I exactly applied the same code :
CREATE SEQUENCE seq_import_trame INCREMENT 1 START 1;
CREATE TABLE import_trame (
id integer NOT NULL DEFAULT nextval('seq_import_trame'),
...,
CONSTRAINT pk_import_trame PRIMARY KEY (id)
);
ALTER SEQUENCE seq_import_trame OWNED BY import_trame.id;
But I have an error while executing script with pgAdmin.
Relation "seq_import_trame" already exist".
Code: 42P07
Line 8: ALTER SEQUENCE.....
It's very strange because 42P07 error is duplicate_table.
And if we don't make the link, the sequence is not dropped when we drop the table.
Any idea ?
I see no problem on DB Fiddle:
Schema (PostgreSQL v9.6)
CREATE SEQUENCE seq_import_trame INCREMENT 1 START 1;
CREATE TABLE import_trame (
id integer NOT NULL DEFAULT nextval('seq_import_trame'),
CONSTRAINT pk_import_trame PRIMARY KEY (id)
);
ALTER SEQUENCE seq_import_trame OWNED BY import_trame.id;
View on DB Fiddle
Check again your script.

SQL Error about syntax error(POSTGRES)

I always get the error on postgres sql can anyone help me
ERROR: Syntaxerror in „(“ LINE 4: Liga_Nr int(1),
^
********** ERROR **********
ERROR: Syntaxerror in „(“ SQL Status:42601 Symbol:79
Here is my code
DROP TABLE IF EXISTS Liga;
Create Table Liga(
Verband varchar(90),
Liga_Nr int(1),
PRIMARY KEY(Liga_Nr)
);
DROP TABLE IF EXISTS Spiel;
CREATE Table Spiel(
);
DROP TABLE IF EXISTS Verein;
CREATE Table Verein(
);
DROP TABLE IF EXISTS Spieler;
CREATE Table Spieler(
PRIMARY KEY(Spieler_ID)
);
Integer types don't accept a parameter. The correct code is:
Create Table Liga(
Verband varchar(90),
Liga_Nr int,
PRIMARY KEY(Liga_Nr)
);
If you want to store a small number, use smallint. You can read about numeric types here.

error while trying to alter a column in a table

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)

sql code for firebird doesn't compile

I am getting strange errors while trying to create a simple database using isql tools from the Firebird package.
The same code for creating a table works for other tables with other names.
I've tried with and without quotes surrounding fields and table names, no success.
It is Firebird 2.5 server version.
The code I'm trying to execute:
SET SQL DIALECT 3;
SET NAMES UTF8;
CREATE DATABASE 'localhost:C:\fuzzdb.fdb' user 'SYSDBA' password 'masterkey'
DEFAULT CHARACTER SET UTF8;
CREATE TABLE RULES (
RULE_ID INTEGER NOT NULL,
IF_FUZZY SMALLINT,
CONSTRAINT PK_RULE_ID
PRIMARY KEY (RULE_ID),
);
CREATE TABLE VARS (
VAR_ID INTEGER NOT NULL,
VRULE_ID INTEGER,
INPOUTP SMALLINT,
RANGE_STRT INTEGER,
RANGE_END INTEGER,
VAR_NAME VARCHAR(40),
FUZ_SET INTEGER,
CONSTRAINT PK_VAR_ID
PRIMARY KEY (VAR_ID)
);
CREATE TABLE FUZZSETS (
FS_ID INTEGER NOT NULL,
FS_NAME VARCHAR(40),
INPOUTP SMALLINT,
PAR1 FLOAT,
PAR2 FLOAT,
PAR3 FLOAT,
PAR4 FLOAT,
PAR5_HEDGE INTEGER,
FUZ_SET INTEGER,
CONSTRAINT PK_FS_ID
PRIMARY KEY (FS_ID)
);
CREATE TABLE FRULES (
FRULE_ID INTEGER NOT NULL,
RULE_ID INTEGER,
VAR_ID INTEGER,
FS_ID INTEGER,
INPOUTP SMALLINT,
CONSTRAINT PK_FRULE_ID
PRIMARY KEY (FRULE_ID)
);
CREATE TABLE LINK_RV (
LINK_RULES INTEGER,
LINK_VARS INTEGER,
CONSTRAINT FK_LINK_RV
PRIMARY KEY (LINK_RULES, LINK_VARS)
);
CREATE TABLE LINK_VARFS (
LINK_VRS INTEGER,
LINK_FS INTEGER,
CONSTRAINT FK_LINK_VARFS
PRIMARY KEY (LINK_VRS, LINK_FS)
);
CREATE TABLE LINK_RLVR (
LINK_RULE INTEGER NOT NULL,
LINK_VR INTEGER NOT NULL,
CONSTRAINT FK_LINK_RLVR
PRIMARY KEY (LINK_RULE, LINK_VR)
);
CREATE TABLE LINK_FRL_RL (
LINK_FRULE INTEGER NOT NULL,
LINK_RULE INTEGER NOT NULL,
CONSTRAINT FK_LINK_FRL_RL
PRIMARY KEY (LINK_FRULE, LINK_RULE)
);
CREATE TABLE LINK_FRL_VAR (
LINK_FRULE INTEGER NOT NULL,
LINK_VAR INTEGER NOT NULL,
CONSTRAINT FK_LINK_FRL_VAR
PRIMARY KEY (LINK_FRULE, LINK_VAR)
);
CREATE TABLE LINK_FRL_FS (
LINK_FSRULE INTEGER NOT NULL,
LINK_FS INTEGER NOT NULL,
CONSTRAINT FK_LINK_FRL_FS
PRIMARY KEY (LINK_FRULE, LINK_FS)
);
ALTER TABLE LINK_FRL_FS
ADD CONSTRAINT FK_LINK_FSRULE
FOREIGN KEY(LINK_FSRULE)
REFERENCES FRULES(FRULE_ID);
ALTER TABLE LINK_FRL_FS
ADD CONSTRAINT FK_LINK_FS
FOREIGN KEY(LINK_FS)
REFERENCES FUZZSETS(FS_ID);
ALTER TABLE LINK_FRL_VAR
ADD CONSTRAINT FK_LINK_FRULE
FOREIGN KEY(LINK_FRULE)
REFERENCES FRULES(FRULE_ID);
ALTER TABLE LINK_FRL_VAR
ADD CONSTRAINT FK_LINK_VAR
FOREIGN KEY(LINK_VAR)
REFERENCES FUZZSETS(VAR_ID);
ALTER TABLE LINK_FRL_RL
ADD CONSTRAINT FK_LINK_FRULE
FOREIGN KEY(LINK_FRULE)
REFERENCES FRULES(FRULE_ID);
ALTER TABLE LINK_FRL_RL
ADD CONSTRAINT FK_LINK_RULE
FOREIGN KEY(LINK_RULE)
REFERENCES RULES(RULE_ID);
CREATE GENERATOR GEN_RULE_ID;
CREATE GENERATOR GEN_VAR_ID;
CREATE GENERATOR GEN_FS_ID;
CREATE GENERATOR GEN_FRULE_ID;
SET TERM ^ ;
CREATE TRIGGER BI_RULES FOR RULES
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.RULE_ID IS NULL) THEN
NEW.RULE_ID = GEN_ID(GEN_RULE_ID, 1);
END^
CREATE TRIGGER BI_VARS FOR VARS
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.VAR_ID IS NULL) THEN
NEW.VAR_ID = GEN_ID(GEN_VAR_ID, 1);
END^
CREATE TRIGGER BI_FUZZSETS FOR FUZZSETS
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.FS_ID IS NULL) THEN
NEW.FS_ID = GEN_ID(GEN_FS_ID, 1);
END^
CREATE TRIGGER BI_FRULES FOR FRULES
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.FRULE_ID IS NULL) THEN
NEW.FRULE_ID = GEN_ID(GEN_FRULE_ID, 1);
END^
SET TERM ; ^
COMMIT;
The output from the isql commmand:
Use CONNECT or CREATE DATABASE to specify a database
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 6, column 3
-)
At line 10 in file c:\fdb.sql
Statement failed, SQLSTATE = 42000
unsuccessful metadata update
-Unknown columns in index FK_LINK_FRL_FS
After line 82 in file c:\fdb.sql
Statement failed, SQLSTATE = 42S02
Dynamic SQL Error
-SQL error code = -204
-Table unknown
-LINK_FRL_FS
-At line 1, column 13.
After line 89 in file c:\fdb.sql
Statement failed, SQLSTATE = 42S02
Dynamic SQL Error
-SQL error code = -204
-Table unknown
-LINK_FRL_FS
-At line 1, column 13.
After line 94 in file c:\fdb.sql
Statement failed, SQLSTATE = 42000
unsuccessful metadata update
-could not find UNIQUE or PRIMARY KEY constraint in table FUZZSETS with specifie
d columns
After line 104 in file c:\fdb.sql
Statement failed, SQLSTATE = 42S11
unsuccessful metadata update
-Index FK_LINK_FRULE already exists
After line 109 in file c:\fdb.sql
Statement failed, SQLSTATE = 42000
unsuccessful metadata update
-Table RULES not found
After line 114 in file c:\fdb.sql
Statement failed, SQLSTATE = 42S02
Dynamic SQL Error
-SQL error code = -204
-Table unknown
-RULES
-At line 1, column 29
At line 130 in file c:\fdb.sql
I don't get why it's impossible to create the first table "RULES" although the commands are similar to other tables.
Even without all the triggers and foreign keys (alter table..) I am getting at leaast the last error.
it says "Unknown columns in index FK_LINK_FRL_FS" but no mention of other similar indexing tables.
I am just starting working with databases and it could be that I missed or mixed something,
but I tried to compile with too many changes and still getting errors.
I've found more or less similar code here
http://sergworks.wordpress.com/category/firebird/
and I was able to compile it without problems.
Could somebody point me in the right direction or show how it is done in another way?
You have an unnessesary comma in the end of the PK constraint:
CONSTRAINT PK_RULE_ID
PRIMARY KEY (RULE_ID),
So the parser expexts definition of field or constraint but it finds ")". Delete the comma and you should be OK.