简体   繁体   中英

Insert into table with value of auto increment column SQL Server

I have a table with primary key auto increment ID column.

In some cases, I would like to insert the value of the auto increment column into another column in the same table (Without update statement).

Is it possible?

Does this ID value go into another column of the same row when it does go in? If so I would think that you could make this other column a calculated column that returns the ID column under certain conditions.

Other than that I can't think of any way you can put a value into place without an update or insert statement of some kind. However when you end up doing it with an update or insert statement you can get the last ID generated using SCOPE_IDENTITY(), and you can also get the values that were inserted in some other statement by adding an OUTPUT clause. See http://msdn.microsoft.com/en-us/library/ms174335.aspx .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM