NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert table while leaving the primary key empty

Dear Folks,

I have several LabVIEW program running at different locations writing (INSERT) to the same table of the same database.  I've set the Primary Key of the table auto-increment integer.

The problem is: I want to leave the primary key increment by itself while fill in other fields of the same record using DB TOOLS INSERT DATA, but I HAVE TO bundle an integer into the cluster (of the same size / data type of each field of a record) that corresponds to that integer primary key. Otherwise I get an error.

If I do that, then there is another problem: since I have several programs writing to the same table asychronously, I can't really keep track of the most current primary key number. Of course I can run a query, but while the query result is being returned to one LabVIEW program, another LabVIEW program might have already added a new record (therefore the primary key number changed).

Please show me a way to insert table without having the primary key bundled in.

Thanks a lot!
Toutiao


0 Kudos
Message 1 of 3
(3,221 Views)
Toutiao,
What error are you being given? I'm really not a dabase expert, so when you say "I've set the Primary Key of the table auto-increment integer." I'm not quite sure I know what that means. It seems like you're telling your database to act one way, but then trying to get LabVIEW to interact with it in a different fashion. Can you provide more clarification?
 
 
Chris C
0 Kudos
Message 2 of 3
(3,201 Views)
Toutiao -
My understanding is that INSERT sql commands do not allow you to return or query for the value of the primary key. I think that your options are to:
1) Use a manual generated primary key, such as a guid, and use this in your INSERT statements.
2) Use a stored procedure to return a new primary key value, and use this in your INSERT statements (for example, Oracle has Sequences to do this)
3) Use a SELECT statement instead of an INSERT and fetch the primary key value after you create the record. You typically need to use a keyset cursor and some databases do not support this.
4) Use stored procedures to pass all the data that needs to be written to the database and let the stored procedure do the work for you.
Scott Richardson
https://testeract.com
0 Kudos
Message 3 of 3
(3,183 Views)