|
|
|
Triggers
|
|||
|---|---|---|---|
|
#18+
Недавно столкнулся с проблемой, которая осложняет написание скрипта: хочется чтобы создание триггера было условным, то есть типа: if @Condition CREATE TRIGGER trMain ON Main FOR INSERT AS <body> Но MSSQL ругается на такую конструкцию и хочет чтобы перед CREATE TRIGGER обязательно стояло GO. Если кто-то знает, помогите справиться с проблемой... ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 07.07.2002, 21:47:00 |
|
||
|
Triggers
|
|||
|---|---|---|---|
|
#18+
Тут уже один чел подсказывал: sp_executesql(...) ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 07.07.2002, 23:42:40 |
|
||
|
Triggers
|
|||
|---|---|---|---|
|
#18+
Seaparate the script that contains CREATE TRIGGER into a separate script file (MyTrigger.SQL) and invoke it with xp_cmdshell if the @Condition is TRUE, e.g.: If @Condition exec master.dbo.xp_cmdshell 'osql -S MyServer -d MyDatabase -E -i "MyTrigger.SQL"' Hope it helps. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 08.07.2002, 00:08:16 |
|
||
|
Triggers
|
|||
|---|---|---|---|
|
#18+
Re:Robert Djabaro If I can write in english as you, I'l be in Canberra. Поставьте, наконец, поддержку русского на свой лаптоп. Если не хватает места, то можно удалить игры, или всю директорию HELP. Рад появлению высококвалифицированного участника форума. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 08.07.2002, 00:25:22 |
|
||
|
Triggers
|
|||
|---|---|---|---|
|
#18+
2Cat2 1) Помнишь похожий вопрос девушки? Я ответил (последним) точно так же, как сейчас Robert. 2) Тоже очень рад. P.S. Ё-моё. Выходные прошли, а ни хрена не сделал, что надо было сделать. Как это на меня похоже. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 08.07.2002, 00:39:29 |
|
||
|
Triggers
|
|||
|---|---|---|---|
|
#18+
sp_executesql sp_executesql is a system stored procedure that you can use in place of "exec" to execute your dynamic sql. This allows you to have parameters in your dynamic query and pass them in. The end result is that SQL Server will try to cache the execution plan for your query giving you some of the advantages of a fully compiled query. An example Declare @SQL nVarChar(1000) --N.B. string must be unicode for sp_executesql SELECT @SQL = 'SELECT * FROM pubs.DBO.Authors WHERE au_lname = @AuthorName' Exec sp_executesql @SQL, N'@AuthorName nVarChar(50)', @AuthorName = 'white' The first parameter here is the SQL statement, then you must declare the parameters, after that you pass the in parameters as normal, comma separated. sp_executesql is also useful when you want to execute code in another database as it will run code in the context of it's database, rather than the one it was called from. Try this from a database that is not Pubs Create View pubs.dbo.Auths AS (SELECT au_id, au_lname, au_fname FROM Authors) You will get this error: 'CREATE VIEW' does not allow specifying the database name as a prefix to the object name. So you build the dynamic sql, then run it in Pub's copy of sp_executesql I.E. Declare @SQL nVarChar(1000) Select @SQL = 'Create View Auths AS (SELECT au_id, au_lname, au_fname FROM Authors)' Execute pubs.dbo.sp_executesql @sql ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 08.07.2002, 00:49:28 |
|
||
|
Triggers
|
|||
|---|---|---|---|
|
#18+
Пардон, забыл указать автора, приведённого мною текста: мусьё Merkin (www.sqlteam.com). ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 08.07.2002, 01:13:12 |
|
||
|
|

start [/forum/topic.php?fid=46&msg=32035476&tid=1821956]: |
0ms |
get settings: |
7ms |
get forum list: |
14ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
67ms |
get topic data: |
7ms |
get forum data: |
2ms |
get page messages: |
27ms |
get tp. blocked users: |
1ms |
| others: | 234ms |
| total: | 365ms |

| 0 / 0 |
