From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

database :Auto increment in SQL server ID

Hi,

How can I do auto increment in SQL server primary column ID. Actualy I am writing the data into the SQL datbase table using LabVIEW and I wanted to set the auto increment to the primary key column ID.  I have three column in TEST_REPORT table i.e  Test_ID, Test_No and Test_Result. I wanted to set Test_ID as a primary key and set as a auto increment and write the value for only Test_No and Test_Result column

When ever I am writing data into table the Test_ID is not getting auto incremented. I set that auto increment manualy through SQL server management studio.

 

 

Please help me to fix this issue.

0 Kudos
Message 1 of 11
(5,556 Views)
This is really a SQL server question, but you can define an integer primary key column to be auto incrementing when you create the table.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 11
(5,546 Views)

Hello Mike,

 We have to write data in all column. How we can ignore the no of data and column match error. 

0 Kudos
Message 3 of 11
(5,533 Views)
In your insert, you specify the names of the columns and the data. For example, say you have a table with three numeric columns, foo1, foo2 and foo3. If you could insert into just the last two using a syntax like:

INSERT INTO myTable
(foo2, foo3)
VALUES
(42, 3.14)
;

Mike...

PS don't use the database connectivity toolkit. It over-complicates things massively.

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 11
(5,527 Views)
If you can do auto increment it's well and good because that satisfy your needs....

If not you can query for TEST ID at initially and increment and write into server along with rest data.... keep the TEST ID in loop and increment every time you upload....

It's not that you, need to query for TEST ID . You can get once and use the same until your application exits
0 Kudos
Message 5 of 11
(5,449 Views)
No need to query for TEST ID every time..... only once for a single launch
0 Kudos
Message 6 of 11
(5,447 Views)

Hi Palanivel,

Thanks for the suggestion.

Initially I was using same logic "query for TEST ID at initially"  but I have to query data from more than 20 tables  and write into it and its taking lots of space and query time.

I am just looking for alternative of this. 

Actually I am setting the auto incremnt  for TEST ID  through the SQL server managemnt studio but when ever I ignore the TEST ID column and write the data in rest column.  

I gets the error message  "Insert Error: Column name or number of supplied values does not match table definition".  

0 Kudos
Message 7 of 11
(5,229 Views)
Since you have not attached your code or the query, out is impossible to say where you made the mistake.
0 Kudos
Message 8 of 11
(5,219 Views)

Dear Dennis,

I have attached the VI.

Also I have another issue, I have to read the data from the SQL table and table contain three column as per attached jpg image.

Data column contain the array value. I have to read the individiual row array value and use it for other calculation.There is no limit of no of row (array value) in Data Column of  SQL table . Data available in SQL server shown in attached image.

 

 

Thanks,

 

0 Kudos
Message 9 of 11
(5,211 Views)
Can you attach snippets of the code? I'm posting from my phone.
0 Kudos
Message 10 of 11
(5,173 Views)