Jump to content

How to get an id in a SQL database


Recommended Posts

Hello: I would like to know how can I get in Labview 2009 working with SQL Server database, the id (primary key) of any data once I´ve inserted?

im not a database expert but i reckon you can query the Identifier column of that table and sort it in descending order, the 1st item will be the latest identifier that you have just inserted.

it will b something like: SELECT TOP 1 Identifier FROM Mytable ORDER BY DESC

Or you can just Google for a built-in function that returns the latest ID lightbulb.gif

Regards,

Edited by Minh Pham
  • Like 1
Link to comment

im not a database expert but i reckon you can query the Identifier column of that table and sort it in descending order, the 1st item will be the latest identifier that you have just inserted.

it will b something like: SELECT TOP 1 Identifier FROM Mytable ORDER BY DESC

Or you can just Google for a built-in function that returns the latest ID lightbulb.gif

Regards,

Actually I had found that solution yesterday night, jejeje and it worked perfectly, anyway thanks for your fast collaboration  

To be sure you get the right Identity/ID/Identifier of a recently inserted row, you should call execute this query:

MSSQL:

SELECT SCOPE_IDENTITY()

do not use the SELECT @@IDENTITY command it can give you unwanted behavior.

http://msdn.microsof...y/ms190315.aspx

MYSQL:

SELECT LAST_INSERT_ID()

Cheers,

Mikael

So help ful mikael, it made me clear some things, yesterday I was trying with SELECT LAST_INSERT_ID() but working with MSSQL : ) 

regards

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.