Home>

In Microsoft SQL Server Management Studio 18

SELECT IDENT_CURRENT ('KEYWORD')


To get the current value of the IDENTITY column.
I want to get and store the current value of the IDENTITY column of another table in a table

INSERT INTO [dbo]. [IMAGEKEYWORD] (ImageID, Keyword)
SELECT IDENT_CURRENT ('IMAGE', 'KEYWORD') // 'IMAGE' and 'KEYWORD' are in separate tables with IDENTITY column.
Msg 174, Level 15, State 1, Line 2
The ident_current function requires 1 argument (s).</Code></pre>
<p><br />
Is displayed and you cannot continue.</p>
<pre><code data-language = "SQLServer">INSERT INTO [dbo]. [IMAGEKEYWORD] (ImageID, Keyword)
SELECT IDENT_CURRENT ('IMAGE') SELECT IDENT_CURRENT ('KEYWORD')
Msg 120, Level 15, State 1, Line 1
The number of SELECT values ​​must match the number of INSERT columns.
The select list for the INSERT statement contains fewer items than the insert list.


Is displayed and cannot be executed.
Please tell me how I can do it.

>>Development environment
Microsoft SQL Server Management Studio 18
>>Search
I'm not searching because I don't know how to search.

  • Answer # 1

    I think the error message is as it is.
    There is also a web service that translates if you don't understand English.
    Translated by Google.

    The ident_current function requires 1 argument (s).

    The ident_current function requires one argument.

    The select list for the INSERT statement contains fewer items than the insert list.The number of SELECT values ​​must match the number of INSERT columns.

    The select list of the INSERT statement contains fewer items than the insert list. The number of SELECT values ​​must match the number of INSERT columns.

  • Answer # 2

    Get into the habit of checking the manual. INSERT ... SELECT syntax

  • Answer # 3

    How about using SCOPE_IDENTITY ()?

    The example query below is automatically generated by Visual Studio, but ProductID is the IDENTITY column.

    INSERT INTO [Products] ([ProductName] ...) VALUES (@ProductName ...);
    SELECT ProductID, ProductName ... FROM Products WHERE (ProductID = SCOPE_IDENTITY ()) ";