gpt4 book ai didi

SQL 错误 - 语法错误

转载 作者:行者123 更新时间:2023-12-02 08:48:59 24 4
gpt4 key购买 nike

我有以下 T-SQL 查询来从一系列表中删除一条记录:

DELETE FROM config INNER JOIN config_profile ON config.config_id = config_profile.config_id
INNER JOIN config_page ON config_profile.config_profile_id = config_page.config_profile_id
INNER JOIN config_field ON config_page.config_page_id = config_field.config_page_id
INNER JOIN config_constraint ON config_field.config_field_id = config_constraint.config_field_id
INNER JOIN config_constraint_type ON config_constraint.config_constraint_type_id = config_constraint_type.config_constraint_type_id
WHERE config.config_name = 'ConfigName' AND config_profile.profile_name = 'ProfileName'

但它不断抛出错误:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'INNER'.

看着它,我不确定我错过了什么。如有任何帮助,我们将不胜感激。

最佳答案

你需要两个 FROM,我知道这很奇怪

DELETE 
FROM CONfig
FROM
config
INNER JOIN config_profile ON config.config_id = config_profile.config_id
INNER JOIN config_page ON config_profile.config_profile_id = config_page.config_profile_id
INNER JOIN config_field ON config_page.config_page_id = config_field.config_page_id
INNER JOIN config_constraint ON config_field.config_field_id = config_constraint.config_field_id
INNER JOIN config_constraint_type ON config_constraint.config_constraint_type_id = config_constraint_type.config_constraint_type_id
WHERE config.config_name = 'ConfigName' AND config_profile.profile_name = 'ProfileName'

如果你看online help这是语法

[ WITH <common_table_expression> [ ,...n ] ]
DELETE
[ TOP (expression ) [ PERCENT ] ]
[ FROM ]
{ <object> | rowset_function_limited
[ WITH ( <table_hint_limited> [ ...n ] ) ]
}
[ <OUTPUT Clause> ]
[ FROM <table_source> [ ,...n ] ]
[ WHERE { <search_condition>
| { [ CURRENT OF
{ { [ GLOBAL ] cursor_name }
| cursor_variable_name
}
]
}
}
]
[ OPTION ( <Query Hint> [ ,...n ] ) ]
[; ]

<object> ::=
{

[ server_name.database_name.schema_name.
| database_name. [ schema_name ] .
| schema_name.
]
table_or_view_name
}

第一个来自

FROM Is an optional keyword that can be used between the DELETE keyword and the target table_or_view_name, or rowset_function_limited.

第二个 From 是

FROM Specifies an additional FROM clause. This Transact-SQL extension to DELETE allows specifying data from and deleting the corresponding rows from the table in the first FROM clause.

This extension, specifying a join, can be used instead of a subquery in the WHERE clause to identify rows to be removed.

For more information, see FROM (Transact-SQL).

正如托尼指出的那样,您可以选择删除第一个 FROM,以便它更具可读性

DELETE 
Config
FROM
config ....

关于SQL 错误 - 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4431089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com