Chandrahas Balleda
Chandrahas Balleda

Reputation: 2832

SQL - Cannot print values from 'inserted' table

I have heard that the 'inserted' table automatically stores the last inserted record of any table temporarily.I was able to get the values from this inserted table when using triggers but not manually as

insert into samantha (id , name) values (11,'has')
select *from inserted

I am getting the error message as

Invalid object name 'inserted'.

Can you please give the reason.Thanks in advance

Upvotes: 1

Views: 1081

Answers (2)

James Z
James Z

Reputation: 12317

There is inserted table, but it can be only used with output clause, with something like this:

insert into samantha (id , name) 
output inserted.*
values (11,'has')

If you have an identity field and you want the latest value from it, you can use SCOPE_IDENTITY() -function too:

insert into samantha (id , name) 
values (11,'has')

select SCOPE_IDENTITY()

Upvotes: 4

huzain07
huzain07

Reputation: 1171

try use SELECT LAST_INSERT_ID() from samantha

Upvotes: 0

Related Questions