Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / hint OPTION(FORCE ORDER) in user-defined function:compilation error / 4 сообщений из 4, страница 1 из 1
12.11.2002, 21:33:43
    #32067187
vantive
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
hint OPTION(FORCE ORDER) in user-defined function:compilation error
How to use hint OPTION(FORCE ORDER) in user-defined function?

create table a(i int ,val char )
create table b( i int, data char)
go
create function my_func (@v char)
returns table as
return ( select b.* from b JOIN a
ON a.id=b.id
OPTION(FORCE ORDER)
)
go
Output:
Server: Msg 156, Level 15, State 1, Procedure my_func, Line 5
Incorrect syntax near the keyword 'OPTION'.
...
Рейтинг: 0 / 0
12.11.2002, 22:02:25
    #32067190
Glory
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
hint OPTION(FORCE ORDER) in user-defined function:compilation error
Choose in QA - Query - Show Execution Plan and check this script

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
select b.* from syscolumns b JOIN sysobjects a ON a.id=b.id 
select b.* from syscolumns b JOIN sysobjects a ON a.id=b.id OPTION(FORCE ORDER) 
go

if object_id('my_func') is not null drop function my_func
go
create function dbo.my_func() 
returns table as 
return(select b.* from syscolumns b JOIN sysobjects a ON a.id=b.id) 
go


select * from dbo.my_func()
select * from dbo.my_func() OPTION(FORCE ORDER) 
...
Рейтинг: 0 / 0
12.11.2002, 22:24:32
    #32067195
vantive
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
hint OPTION(FORCE ORDER) in user-defined function:compilation error
Thanks, but ...
1) I want to hide this hint from users , which will use this function, it means I want keep hint in the body of function.
2) interesting point is that other hints, like NOLOCK, can
be embedded in user-defined function without any problem.

Thanks again
...
Рейтинг: 0 / 0
12.11.2002, 22:47:45
    #32067198
Glory
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
hint OPTION(FORCE ORDER) in user-defined function:compilation error
You can use several table hints in same query (for each table, join, ect.) but only one OPTION clause.

For example you can't create a view with OPTION clause. But you can create a view with several table hints.

So a think it's the feature. OPTION hint(s) should be used throughout the entire query . So it's impossible that something in FROM Clause (inline UDF, view) already contains OPTION hint(s).
...
Рейтинг: 0 / 0
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / hint OPTION(FORCE ORDER) in user-defined function:compilation error / 4 сообщений из 4, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]