|
|
|
Any advantages of using a cursor to retrieve just one record?
|
|||
|---|---|---|---|
|
#18+
In the application I am maintaining there is a practice of storing the newly inserted identity in a special global temporary table for use from within the procs or scripts. The way they retrieve the stored value is this: EXEC ('DECLARE id CURSOR FOR select id from ' + @identity_table_name + ' WHERE table_name = ' + "'" + @table_name + "'") OPEN id FETCH id INTO @some_id DEALLOCATE id Does not make sense for me. Why may they want to build up this stuff instead of a simple EXEC ('SELECT @some_id = id from ' + @identity_table_name + ' WHERE table_name = ' + "'" + @table_name + "'") ??? In the rest of the code they strictly avoid using cursors and stick with SELECT TOP 1 instead. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 24.07.2002, 20:41:18 |
|
||
|
Any advantages of using a cursor to retrieve just one record?
|
|||
|---|---|---|---|
|
#18+
А зачем вообще так делать? Можно написать процедуру (таблица я так понимаю уже создана), которая на вход получает имя таблицы (или имя ключа), а в выходной параметр выдает значение ключа... Нет никакого смысла здесь использовать курсоры. Курсоры очень тормозят работу сервера... ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 24.07.2002, 20:55:28 |
|
||
|
Any advantages of using a cursor to retrieve just one record?
|
|||
|---|---|---|---|
|
#18+
Maybe your developers want use identity value right after EXEC(). In this case you can use this script for return value from dynamic query like this Код: plaintext 1. 2. 3. 4. or like this Код: plaintext 1. 2. 3. 4. 5. 6. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 24.07.2002, 21:24:56 |
|
||
|
Any advantages of using a cursor to retrieve just one record?
|
|||
|---|---|---|---|
|
#18+
2All: The reason for still using this practice is that it is a corporate standard. You all know that it is like a concrete wall... You can not break it, you can only drive along it. The reason for storing @@identity in a ## table is that they have i, u & d triggers in each and every table and those triggers populate other tables with their own identities and they also call procs that do the same thing. My concern is about the way they retrieve that one value from that table - why necessarily using a cursor where a simple select would do? PS: Sorry for writing in English - I can't get ahold of w2k CD to install ru locale... And I hate translit. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 25.07.2002, 19:35:21 |
|
||
|
|

start [/forum/topic.php?desktop=1&fid=46&tid=1821562]: |
0ms |
get settings: |
5ms |
get forum list: |
12ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
44ms |
get topic data: |
10ms |
get forum data: |
2ms |
get page messages: |
39ms |
get tp. blocked users: |
1ms |
| others: | 203ms |
| total: | 320ms |

| 0 / 0 |
