Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

How to Create MS SQL Server Table With PK and Insert into it

I cannot get this to work no matter what I try.
I want a tMSSqlOutput component to "Create table if not exists" (because the table will not initially exist). The tMap feeding into the tMSSqlOutput has all of the columns I want to go into the DB with the exception of an "id" column which is to serve as an auto-increment PK. I don't know how to get the "id" column in there. I have tried everything. This is a really simple concept, but I find this impossible to do in talend.
Labels (2)
5 Replies
_AnonymousUser
Specialist III
Specialist III
Author

If I try adding an "id" to the schema coming out of my tMap and to the tMSSqlOutput schema, I get hit with a
"Identity column 'id' contains invalid INCREMENT." error. There's no where to specify an increment value in the schema editor!!! I can say the column is the key, I can say the DB type is INT IDENTITY, I can say the column is non-nullable, I can specifiy a length, precision, default, or comment...but no INCREMENT.
So then, if I go into my tMSSqlOutput component and check the "Specify identity field", logically I think that maybe if I specify the "Step" to be 1, that'll set the INCREMENT. Sounds like that should do the trick right? WRONG. I get another error. This time a "More than one column IDENTITY constraint specified for column 'id'". I never specified multiple identity columns. In the schema I said I wanted the "id" column to be my PK and an INT IDENTITY type. In the tMSSqlComponent I checked "Specify identity field", chose my "identity field" to be my "id" column, and set the step to 1. Where am I supposedly choosing more than one IDENTITY column?
_AnonymousUser
Specialist III
Specialist III
Author

Here's another funky thing I noticed. If in the schema editor, for my id column, I set DB Type = INT IDENTITY, nothing for Length, 10 for Precision. I went to look in SQL server at the table that Talend created, and that "10" for precision ended up being the Identity Seed for the "id" column in my table in SQL Server. Something is clearly not mapped right.
Anonymous
Not applicable

Hello
Yes, it is impossible to create a table with auto-increment filed on tMysqlOutput component. At the moment, you can use tMysqlTableList to iterate each table and detect the table if exists, if not, use a tMysqlRow to custom the 'create table' sql.
Best regards
Shong
_AnonymousUser
Specialist III
Specialist III
Author

Thanks Shong, I was able to use a tMSSqlRow component to run a SQL command to create the table at the beginning of my script.
Anonymous
Not applicable

It is to late to reply, but it may be useful to somebody.
It can be done with any MSSQL component, Just set the parameters as:
Key=True
DB TYPE=INT IDENTITY
LENGTH=1
PRECISION=1
0683p000009MBJk.png
you can always use tCreateTable.