Этот баннер — требование Роскомнадзора для исполнения 152 ФЗ.
«На сайте осуществляется обработка файлов cookie, необходимых для работы сайта, а также для анализа использования сайта и улучшения предоставляемых сервисов с использованием метрической программы Яндекс.Метрика. Продолжая использовать сайт, вы даёте согласие с использованием данных технологий».
Политика конфиденциальности
|
|
|
Insert Into - Identity
|
|||
|---|---|---|---|
|
#18+
Помогите с решением проблемы! В таблице у ключевого поля указано свойство Idenity - Yes, поэтому новые номера присваиваются при добавлении записи автоматически, но вот в этом то и проблема. Была сделана связная таблица содержащая два вторичных ключа, один из них должен быть из выше описанной таблицы. Добавление записей в обе эти таблицы должно быть в одной транзакции. Можно ли после добавления записи в таблицу с Idenity - Yes получить(определить) значение ключа? Спасибо! ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 13.05.2002, 15:16 |
|
||
|
Insert Into - Identity
|
|||
|---|---|---|---|
|
#18+
Есть системная переменная @@Identity, которая содержит последнее созданное в данном соединении значение поля со свойством Identity. Т.е логика примерно следующая: DECLARE @LastIdentity Int BEGIN TRANSACTION INSERT INTO Tab1 (...) VALUES (...) SET @LastIdentity=@@Identity INSERT INTO Tab2 (Tab1_ID, ...) VALUES (@LastIdentity, ...) COMMIT TRANSACTION ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 13.05.2002, 15:31 |
|
||
|
Insert Into - Identity
|
|||
|---|---|---|---|
|
#18+
Цитирую отсюда : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_globals_50u1.asp @@IDENTITY Returns the last-inserted identity value. Syntax @@IDENTITY Return Types numeric Remarks After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY contains the last identity value generated by the statement. If the statement did not affect any tables with identity columns, @@IDENTITY returns NULL. If multiple rows are inserted, generating multiple identity values, @@IDENTITY returns the last identity value generated. If the statement fires one or more triggers that perform inserts that generate identity values, calling @@IDENTITY immediately after the statement returns the last identity value generated by the triggers. If a trigger is fired after an insert action on a table that has an identity column, and the trigger inserts into another table that does not have an identity column, @@IDENTITY will return the identity value of the first insert. The @@IDENTITY value does not revert to a previous setting if the INSERT or SELECT INTO statement or bulk copy fails, or if the transaction is rolled back. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 13.05.2002, 15:40 |
|
||
|
|

start [/forum/topic.php?fid=46&gotonew=1&tid=1822782]: |
0ms |
get settings: |
10ms |
get forum list: |
18ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
90ms |
get topic data: |
11ms |
get first new msg: |
6ms |
get forum data: |
3ms |
get page messages: |
50ms |
get tp. blocked users: |
2ms |
| others: | 261ms |
| total: | 459ms |

| 0 / 0 |
